1 / 11

Introduction to MATLAB

Introduction to MATLAB. Notes to complement on-line demo. MATLAB Overview. What is MATLAB A program that may be used to automate mathematical computations Interpretive environment, calculations at the command line Includes scripting language, you can write programs

Download Presentation

Introduction to MATLAB

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. BAE 1012 Introduction to MATLAB Notes to complement on-line demo

  2. MATLAB Overview BAE 1012 • What is MATLAB • A program that may be used to automate mathematical computations • Interpretive environment, calculations at the command line • Includes scripting language, you can write programs • Rich with engineering oriented functions • Modern engineering tool widely used in engineering • Includes “Toolboxes” for specialty applications • Controls • Signal Processing • Bio-system simulation • Includes block diagram based simulation “Simulink”

  3. Simple Calculations BAE 1012 • Command Line Interpreter • Set variables • A=3 • B=[3,4,7] row vector • C=[3; 4; 7] column vector • D=[1,2;3,4] matrix • Show variables • Who,whos • Clear variables • Clear, clear x • Set iterated list • E=1:0.2:10 (start : increment : end)

  4. Getting help BAE 1012 • Best: • Select Help from the menu (MATLAB 6) • Next Best (UNIX/LINUX): • Use the command HELP from the command prompt • “HELP” Alone for general – list topic areas • “Help topic” for help on “topic” • Topics are divided into general areas • Controls, Signal processing, etc. • Local functions may be added to the local dir • Organized with • General help • Toolbox help

  5. Complex Numbers BAE 1012 • Set number • A=3 + 4i • Magnitude • M=abs(A) • Angle • Alpha=angle(A) • Conjugate • A_star=conj(A) • Imaginary part / real part • Imag_a = imag(A) • Real_a=real(A) • Try sqrt(-1)

  6. Simple Plotting BAE 1012 • Simple x/y plot • x=0:1:20 • x=sin(x) • plot(x,y) • Set line /point type • plot(x,y,’c+’) cyan “+” points • plot(x,y,’c+’,x,y,’y-’) cyan points and yellow line • Set Titles and labels Labels • xlabel(‘X-axis’), Ylabel(‘Y-Axis’) • Title(‘Title’) • Alternative: Use figure menu /Edit/Axis Properties • Set axis titles • Main title • Line properties etc.

  7. 3D plot BAE 1012 • Set x and y values • x = 0:.1:20; • y = 0:.1:20; • Create matrices for “xg – yg” grid • [xg, yg] = meshgrid(x,y); • Calculate an equation for “z” on the grid • z = sin(pi*xg/20).* sin(pi*yg/20); (note the .* for element by element multiplication where xg and yg are 20x20 matricies) • Plot the surface or mesh • surf(x,y,z) or mesh(x,y,z)

  8. Matrix math BAE 1012 • Consider a set of equations: • Given x1,x2 you can find y1,y2. • The more usual problem is y1,y2 are given and you need x1,x2 • Solution: • Write in matrix form and solve

  9. Matrix math BAE 1012 • Example • Set y,A • Y = [ 3 ; 4 ] • A = [ 7 , 4.5; 3.3, 9.1 ] • Find A inverse (A-1) • Ai = inv(A) • Calculate x • x = Ai*y

  10. Additional matrix operations BAE 1012 • Transpose a matrix • (switch rows and columns) • y = y’ • To multiply element by element by a scalar • y = sin(y) .* y (replace each element by “y sin y”)

  11. M-File -programs BAE 1012 • Use File menu to create or open a script file • Use Matlab commands as script • Save into m-file space and then execute by file name on the command line • Example: • Save as sin_surf.m • Execute as sin_surf on the command line for i = 1:30 for j = 1:30 z(i,j) = sin(3.14159 * ((i - 16) ^ 2 + (j - 16) ^ 2) / (7 * 30)) *( j - 1); end end surfc(z)

More Related