This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Matlab Session # 1 Section I : Introduction MATLAB stands for MATrix LABoratory. It has following the features in contrast with usual programming languages: 1. It is an interpreted language , i.e., programs (called script files) are not compiled before execution. When a program is executed, next program statement is read while one statement is under execution; it is interpreted spontaneously and then executed. This has the following implications: a. There are two modes of working in matlab i. Interactive mode: Commands can be directly written and executed at the command prompt (just like executing DOS commands). ii. M-files: A program, which is a sequence of matlab commands, can be stored as a file with extension .m (e.g. lagrange.m) and executed. There are two types of M-files: script files , which are executable programs, and functions , which return a value. b. Mistakes (except for obvious mistakes in syntax) are caught only upon executing the program. c. Simple operations can be performed immediately at command prompt. d. Programs are just a sequence of commands that could otherwise be typed individually at command prompt. In fact we can copy and paste portions of a program on command prompt and execute that fragment. 2. Variables have very different characteristics in matlab a. Variables need not be pre-defined. As a variable name appears, it is created in memory and its type is automatically selected according to the context. However it makes programs more vulnerable to logical errors as a slight misspelling somewhere causes a new variable to be automatically defined. b. All variables reside in a memory area called Workspace . Even after program is finished, the variables are available on the workspace and some simple post- processing can be performed at command prompt. The workspace contents can be viewed in the matlab GUI (Graphical User Interface). c. The variable names can be reused while programming. E.g. if we first say a = 10 then a is an integer variable (type defined automatically). Later, if we say a = 5.10 then a becomes a floating-point number. Again if we say a = * then a becomes a character, d. The smallest variable unit in matlab is a matrix. Even if we say a = 10, it is treated as a matrix having one element. All operations in matlab are matrix operations. e. Answer of the previous operation goes to a pre-defined variable called ans , unless it is redirected to another variable. 3. Because of being an interpreted language and consisting of only matrix variables, programs in matlab run at least 4-5 times slower than same task implemented in other languages. However it is still preferred because it provides many facilities that make programs simple and easy to debug. Complex tasks can be performed in simple and intuitive-looking statements. To optimize the program (so that it runs fast), it is best to use as many built-in commands as possible as these built-in commands are optimized. use as many built-in commands as possible as these built-in commands are optimized....
View Full Document
- Spring '10