# matlab - AE 383 System Dynamics Introduction to Matlab...

This preview shows pages 1–3. Sign up to view the full content.

AE 383 System Dynamics Introduction to Matlab (v.2) Fall 2004 O. Tekinalp 1 Introduction to Matlab Matlab executes the commands given at its command line identified by a double arrow. Some basic commands of Matlab are given below. >> x = exp(-0.2696 * .2)*sin(2*pi*0.3)/(0.01*sqrt(5) * log(18)) x = 13.9428 The expression entered in this fashion is evaluated and x is assigned to the result. >> exp(-0.2696 * .2) ans = 0.9475 If we omit the variable to be assigned, the result is assigned to the global variable “ans” . >> log(2.7183) ans = 1.0000 >> log10(10000) ans = 4 >> COS(pi/3) ??? Capitalized internal function COS; Caps Lock may be on. Note that “ log” is the natural logarithm, whereas “log10” is the base 10 logarithm. sin, cos, tan, asin, acos, atan, exp are some other intrinsic functions. Note that Matlab is case sensitive. Thus, COS(pi/3) gives error! Correct form is: cos(pi/3) >> pi ans = 3.1416 >> 3i+5 ans = 5.0000 + 3.0000i >> (3i+5) /(2i+2) ans = 2.0000 - 0.5000i Also note that “pi” is the usual constant and ij 1 ==− . You can easily assign complex numbers to constants and carry out complex arithmetic. It is a good practice not to use “i” , “j” , and “pi” as variable names. >> [1 2 3] ans = 1 2 3 >> [0.1, 2.3, 4] ans = 0.1000 2.3000 4.0000 Using space or comma between entries may create Row vectors. The whole vector must be placed in square brackets. It is sometimes difficult to type in all the commands. For this reason, you may type your commands to a separate file and execute it from there. 1. Select “New” from the “File” menu. Select “M-file”. 2. Type in all your commands to the M-file you have selected. You may save the file for a later use. 3. Highlight the command or a sequence of commands you would like to execute. Then, right click and select “Evaluate Selection” on the menu that appears. All the commands will be executed at once. This is a very simple way of programming in Matlab.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
AE 383 System Dynamics Introduction to Matlab (v.2) Fall 2004 O. Tekinalp 2 [3.4; 5.23;12.76] ans = 3.4000 5.2300 12.7600
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 10/24/2011 for the course AEE 463 taught by Professor Melin during the Spring '11 term at Middle East Technical University.

### Page1 / 5

matlab - AE 383 System Dynamics Introduction to Matlab...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online