Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to MATLAB

Similar presentations


Presentation on theme: "Introduction to MATLAB"— Presentation transcript:

1 Introduction to MATLAB
MATLAB is a mathematics program that works by either typing in commands or by writing programs Typing x=5*sqrt(83)/(5^3+exp(.2)) will result in x = .3609 MATLAB handles matrix mathematics and complex number arithmetic with ease 1/16/2019 IntroMatlab.ppt

2 Matlab’s Workspace Each command or each program creates a set of variables with values in the workspace Values are kept until you no longer need them Use clear to wipe the workspace clean Use clear x to eliminate the variable x Use clear variables to clear all variables Clear the screen of text by using clc on the command line or choosing Clear Session under Edit in the menu. This does not clear the variables. 1/16/2019 IntroMatlab.ppt

3 Matlab’s Workspace You can check your variables at any time
who generates a listing of all variables whos generates a listing of all variables plus the size, bytes and class of the variables Choosing Show Workspace under the File menu brings up a window showing the same information as whos) Type help who for more detailed information Type the variable to see its value(s) 1/16/2019 IntroMatlab.ppt

4 Matlab Built-In Functions
Matlab commands and functions are broken down into many categories Type help elfun trigonometric functions exponential functions complex number functions rounding/remainder functions 1/16/2019 IntroMatlab.ppt

5 Common Math Functions Trigonometric – cos, sin, tan, atan
Be sure to use radians in the argument Square root – sqrt(2) yields 1.414 Natural Log – log(3) yields Base 10 Log – log10(4) yields .6021 Base 2 Log – log2(4) yields 2 Exponential – exp(2) yields e2 = 1/16/2019 IntroMatlab.ppt

6 Complex Number Functions
Enter in rectangular form x=4+3j or x=4+3i or x=complex(4,3) Magnitude – abs(x) yields 5 Phase angle – angle(x) yields radians Complex conjugate – conj(x) yields 4-3j Real part – real(x) yields 4 Imaginary part – imag(x) yields 3 1/16/2019 IntroMatlab.ppt

7 Matlab – Matrix Math Matrices are rectangular arrays of numbers
Matlab uses matrix math to simplify many calculations Each element in a matrix can be accessed using its row and column – m(row,column) An entire row or column can be accessed to form a vector – m( : ,column) or m(row, : ) 1/16/2019 IntroMatlab.ppt

8 Generating a Vector Generate a vector by listing its values
Rowvector=[ ] Columnvector=[1;2;3;4;5;6;7;8;9] – the semicolon starts a new row Create a row vector with a constant interval T=start value : increment : end value T=0 : 2 : 10 gives T=[ ] T=linspace(start value, end value, number wanted) T=linspace(0,10,5) gives T=[ ] 1/16/2019 IntroMatlab.ppt

9 Generating a Vector You can create a row vector with logarithmic spacing T=logspace(starting power of 10, ending power of 10, number of values wanted) T=logspace(0,2,4) gives T=[ ] 1/16/2019 IntroMatlab.ppt

10 Generating a Matrix You can create a matrix by entering each row with semicolons between each row A = [3 4 –7 ; 5 –7 3 ; –6] A = 5 –7 3 2 0 –6 1/16/2019 IntroMatlab.ppt

11 Matrices and Sets of Equations
Matrices can be used to represent a system of equations and solve it 3x+4y-7z=10 5x-7y+3z=-6 2x-6z=6 The matrix equation implements the above system x 5 – y = or A * S = C 2 0 – z 1/16/2019 IntroMatlab.ppt

12 Matlab Solution of A*S=C
Premultiply both sides by the inverse of A inv(A) * A * S = inv(A) * C Which simplifies to: S = inv(A) * C or x = .3140 Results in S = or y = .6977 or z = 1/16/2019 IntroMatlab.ppt

13 Running Matlab Programs
Under file, select open Find the M-file that you want to run The M-file should appear in the editor window Modify the M-file as needed Under debug, choose run Results should be displayed in the main window Plots should be displayed in new figure windows 1/16/2019 IntroMatlab.ppt


Download ppt "Introduction to MATLAB"

Similar presentations


Ads by Google