{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Matlab_overview

# Matlab_overview - Introduction to MATLAB 1 2 3 4 5 Basic...

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

Introduction to MATLAB 1. Basic functions 2. Vectors, matrices, and arithmetic 3. Flow Constructs (Loops, If, etc) 4. Create M-files 5. Plotting

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

View Full Document
Basic functions MATLAB as a calculator » (3+5)/7 ans = 1.1429 » x = (3+5)/7 x = 1.1429 » x x = 1.1429 + addition - subtraction / division * multiplication ^ power Sum of (3+5) divided by 7 define a variable
Basic function (continued) If you want to see how many variables you have defined so far, you can use the following command: » who Your variables are: ans x » »whos Name Size Bytes Class ans 1x1 8 double array x 1x1 8 double array Grand total is 2 elements using 16 bytes List all the variables in the current MATLAB session List all the variables with details

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

View Full Document
Basic function (continued) Once you have defined variables: » x = -10 x = -10 » y = 5*x y = -50 » x = (3+5)/7 x = 1.1429 *Once you have defined a value for a variable, you can use it to perform algebraic operation *By default, MATLAB displays 4 decimal digit if the value is not an integer
Special Variables In MATLAB, there are some special variables: » pi ans = 3.1416 » i, j, ans = 0+1.0000i ans = 0+1.0000i Value for π Imaginary number by default unless you change them

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

View Full Document
Format By default, the answer only displays 4 decimal places if it is not an integer If you want to change the format of the output: » format long » pi ans = 3.14159265358979 Other format for the output: format short (4 decimal places) format short e (scientific notation) format long (more than 12) format bank (2 decimal place)
Built-in functions In MATLAB, there are many standard built-in functions » z = sin (pi/4) z = 0.7071 » q = log (4) q = 1.3863 Trigonometric function: sin ( ) asin ( ) cos ( ) acos ( ) tan ( ) atan ( ) ** Angle is in radian Elementary function: sqrt ( ) exp ( ) e log ( ) log log10 ( ) log 10

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

View Full Document
Defining a vector (Row vector) MATLAB is a tool for doing computations with vectors & matrices Row Vectors: » v1 = [2 3, 3] v1 = 2 3 3 » length (v1) ans = 3 Name of vector
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}