SlideShare uma empresa Scribd logo
1 de 41
Matlab Lecture 1 - Introduction to MATLAB ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Command Window Command History Workspace Fig: Snap shot of matlab
Entering Matrices - Method 1:Direct entry ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],No need to define  or declare size of A
Entering Matrices - as lists ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Compute the sum  of each column  in A Result in row vector variable ans Transpose  matrix A Result in column vector variable ans Compute the sum  of each row  in A
Entering Matrices - subscripts ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],row col Slow way of finding sum of column 4 Make another copy of A in X ‘ ;’ suppress output Add one element in  column 5, auto  increase size of matrix
Entering Matrices - colon : Operator ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],end start incr ‘ 0’ to ‘pi’ with incr. of ‘pi/4’ First  k  elements of the  j th  column in A last col Short-cut for “all rows”
Expressions & built-in functions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Elementary functions Complex number Special functions Built-in constants (function)
Entering Matrices  Method 2: Generation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Entering Matrices - Method 3 & 4:  Load & M-File ,[object Object],[object Object],[object Object],[object Object],magik.dat ,[object Object],[object Object],[object Object],[object Object],[object Object],magik.m Three dots (…) means continuation to next line ,[object Object],.m files can be run by just typing its name in Matlab ,[object Object],Read data from file into variable  magik
Entering Matrices - Concatenate & delete ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2nd column deleted
MATLAB as a calculator ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example revisited ,[object Object],[object Object],[object Object],[object Object],[object Object]
How to write an M-file ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Jump to here if TRUE Jump to here if FALSE
Example of a MATLAB Function File ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example of a MATLAB Function File ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
MATLAB Function Files ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Decision making in MATLAB ,[object Object],[object Object],[object Object],[object Object],[object Object]
Roots of ax 2 +bx+c=0  ,[object Object],[object Object],[object Object],[object Object],[object Object]
One possible M-file ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
My M-file ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Header Initialisation Calculate  Δ Make decisions based on value of  Δ
Command Window ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
MATLAB Graphics_ Creating a Plot ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
PLOTTING MULTIPLE CURVES IN THE SAME PLOT  There are two methods for plotting two curves in one plot: ,[object Object],[object Object]
USING THE PLOT COMMAND TO PLOT MULTIPLE CURVES  The command: plot(x,y,u,v)  plots y versus x and v versus u on the same plot. By default, the computer makes the curves in different colors. The curves can have a specific style by using: plot(x,y,’color_linestyle_marker’,u,v, ’color_linestyle_marker’) More curves can be added.
Plot  symbols commands ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Plot the function below on a log-log graph. ,[object Object],[object Object],[object Object],[object Object]
 
x=[0:0.1:10]; y=500-0.5*9.81*x.^2; xd=[0:10]; yd=[500 495 490 470 430 390 340 290 220 145 60]; plot(x,y,'g',xd,yd,'mo--') xlabel('TIME (s)') ylabel('HEIGHT (m)') title('Height as a Function of Time') legend('Model','Data') axis([0 11 0 600]) text(1,100,'Comparison between theory and experiment') EXAMPLE OF A FORMATTED PLOT WITH TWO CURVES Below is the script file of the falling object plot in lecture 4. Plot y versus x in green, and plot yd versus xd in magenta, circle markers, and dashed line.  Creating a vector of time (data) xd  Calculated height y for each x  Creating a vector of time x  Creating a vector of height (data) yd
A PLOT WITH TWO CURVES
Subplots For example, the command: subplot(3,2, p ) Creates 6 plots arranged in 3 rows and 2 columns. subplot(3,2,1) subplot(3,2,2) subplot(3,2,3) subplot(3,2,5) subplot(3,2,4) subplot(3,2,6)
Example:  Plot the 3-D surface described by the equation,     in the region in the x-y plane from x = -5 to 5 and y = -4 to 4. Step 1) solve the equation for z, (continued on the next slide) 3-D Plotting
Step 2) create two vectors  x   and  y  . The values of  x  and   y  will determine the region in the xy plane over which the surface is plotted.  >>   x  = linspace(-3,3,7);  >>   y  = linspace(-2,2,5);     Step 3) Use the  meshgrid  function to create two matrices,  X  and  Y   .  We will use these to compute  Z .  >>   [X , Y]  = meshgrid(x,y)
X = Y =
5- Step 4) compute  Z  by using the  X  and  Y  created by  meshgrid , >>  R  = sqrt(X.^2+Y.^2); >>   Z  = cos(X).*cos(Y).*exp(-R./4) Z  =
5- Step 4) compute  Z  by using the  X  and  Y  created by  meshgrid , >>  R  = sqrt(X.^2+Y.^2); >>   Z  = cos(X).*cos(Y).*exp(-R./4); Step 5) graph in 3-D by applying the surface function,   >>   surf(X,Y,Z);
Subplots ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Mesh & surface plots ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
MATLAB Graphics - Subplots ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
MATLAB Environment (1) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

Mais conteúdo relacionado

Mais procurados

5.2 Strong Induction
5.2 Strong Induction5.2 Strong Induction
5.2 Strong Induction
showslidedump
 
Lesson02 Vectors And Matrices Slides
Lesson02   Vectors And Matrices SlidesLesson02   Vectors And Matrices Slides
Lesson02 Vectors And Matrices Slides
Matthew Leingang
 
Cursor implementation
Cursor implementationCursor implementation
Cursor implementation
vicky201
 

Mais procurados (20)

Advanced MATLAB Tutorial for Engineers & Scientists
Advanced MATLAB Tutorial for Engineers & ScientistsAdvanced MATLAB Tutorial for Engineers & Scientists
Advanced MATLAB Tutorial for Engineers & Scientists
 
Importance of matlab
Importance of matlabImportance of matlab
Importance of matlab
 
Chapter 2: Relations
Chapter 2: RelationsChapter 2: Relations
Chapter 2: Relations
 
1551 limits and continuity
1551 limits and continuity1551 limits and continuity
1551 limits and continuity
 
5.2 Strong Induction
5.2 Strong Induction5.2 Strong Induction
5.2 Strong Induction
 
Parsing LL(1), SLR, LR(1)
Parsing LL(1), SLR, LR(1)Parsing LL(1), SLR, LR(1)
Parsing LL(1), SLR, LR(1)
 
Initial Value Problems
Initial Value ProblemsInitial Value Problems
Initial Value Problems
 
system linear equations and matrices
 system linear equations and matrices system linear equations and matrices
system linear equations and matrices
 
Functions
FunctionsFunctions
Functions
 
Generating function
Generating functionGenerating function
Generating function
 
Matlab matrices and arrays
Matlab matrices and arraysMatlab matrices and arrays
Matlab matrices and arrays
 
Stacks
StacksStacks
Stacks
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introduction
 
linear transfermation.pptx
linear transfermation.pptxlinear transfermation.pptx
linear transfermation.pptx
 
Matlab intro
Matlab introMatlab intro
Matlab intro
 
Differential equation and Laplace Transform
Differential equation and Laplace TransformDifferential equation and Laplace Transform
Differential equation and Laplace Transform
 
Limit of Function And Its Types
Limit of Function And Its TypesLimit of Function And Its Types
Limit of Function And Its Types
 
Lesson02 Vectors And Matrices Slides
Lesson02   Vectors And Matrices SlidesLesson02   Vectors And Matrices Slides
Lesson02 Vectors And Matrices Slides
 
Cursor implementation
Cursor implementationCursor implementation
Cursor implementation
 
The principle of inclusion and exclusion for three sets by sharvari
The principle of inclusion and exclusion for three sets by sharvariThe principle of inclusion and exclusion for three sets by sharvari
The principle of inclusion and exclusion for three sets by sharvari
 

Semelhante a Matlab1

More instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docxMore instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docx
gilpinleeanna
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
agnesdcarey33086
 

Semelhante a Matlab1 (20)

Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
 
MATLAB-Introd.ppt
MATLAB-Introd.pptMATLAB-Introd.ppt
MATLAB-Introd.ppt
 
An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginners
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
Matlab booklet
Matlab bookletMatlab booklet
Matlab booklet
 
Matlab Basic Tutorial
Matlab Basic TutorialMatlab Basic Tutorial
Matlab Basic Tutorial
 
Es272 ch1
Es272 ch1Es272 ch1
Es272 ch1
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projects
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
 
Tutorial2
Tutorial2Tutorial2
Tutorial2
 
More instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docxMore instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docx
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulinkMATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
 
Matlab ch1 intro
Matlab ch1 introMatlab ch1 intro
Matlab ch1 intro
 
COMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptxCOMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptx
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
 

Matlab1

  • 1.
  • 2. Command Window Command History Workspace Fig: Snap shot of matlab
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26. USING THE PLOT COMMAND TO PLOT MULTIPLE CURVES The command: plot(x,y,u,v) plots y versus x and v versus u on the same plot. By default, the computer makes the curves in different colors. The curves can have a specific style by using: plot(x,y,’color_linestyle_marker’,u,v, ’color_linestyle_marker’) More curves can be added.
  • 27.
  • 28.
  • 29.  
  • 30. x=[0:0.1:10]; y=500-0.5*9.81*x.^2; xd=[0:10]; yd=[500 495 490 470 430 390 340 290 220 145 60]; plot(x,y,'g',xd,yd,'mo--') xlabel('TIME (s)') ylabel('HEIGHT (m)') title('Height as a Function of Time') legend('Model','Data') axis([0 11 0 600]) text(1,100,'Comparison between theory and experiment') EXAMPLE OF A FORMATTED PLOT WITH TWO CURVES Below is the script file of the falling object plot in lecture 4. Plot y versus x in green, and plot yd versus xd in magenta, circle markers, and dashed line. Creating a vector of time (data) xd Calculated height y for each x Creating a vector of time x Creating a vector of height (data) yd
  • 31. A PLOT WITH TWO CURVES
  • 32. Subplots For example, the command: subplot(3,2, p ) Creates 6 plots arranged in 3 rows and 2 columns. subplot(3,2,1) subplot(3,2,2) subplot(3,2,3) subplot(3,2,5) subplot(3,2,4) subplot(3,2,6)
  • 33. Example: Plot the 3-D surface described by the equation, in the region in the x-y plane from x = -5 to 5 and y = -4 to 4. Step 1) solve the equation for z, (continued on the next slide) 3-D Plotting
  • 34. Step 2) create two vectors x and y . The values of x and y will determine the region in the xy plane over which the surface is plotted. >> x = linspace(-3,3,7); >> y = linspace(-2,2,5); Step 3) Use the meshgrid function to create two matrices, X and Y . We will use these to compute Z . >> [X , Y] = meshgrid(x,y)
  • 35. X = Y =
  • 36. 5- Step 4) compute Z by using the X and Y created by meshgrid , >> R = sqrt(X.^2+Y.^2); >> Z = cos(X).*cos(Y).*exp(-R./4) Z =
  • 37. 5- Step 4) compute Z by using the X and Y created by meshgrid , >> R = sqrt(X.^2+Y.^2); >> Z = cos(X).*cos(Y).*exp(-R./4); Step 5) graph in 3-D by applying the surface function, >> surf(X,Y,Z);
  • 38.
  • 39.
  • 40.
  • 41.