SlideShare una empresa de 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]

Más contenido relacionado

La actualidad más candente

Job sequencing with deadline
Job sequencing with deadlineJob sequencing with deadline
Job sequencing with deadlineArafat Hossan
 
Importance of matlab
Importance of matlabImportance of matlab
Importance of matlabkrajeshk1980
 
Matrix operations in MATLAB
Matrix operations in MATLABMatrix operations in MATLAB
Matrix operations in MATLABSaloni Singhal
 
PROLOG: Database Manipulation In Prolog
PROLOG: Database Manipulation In PrologPROLOG: Database Manipulation In Prolog
PROLOG: Database Manipulation In PrologDataminingTools Inc
 
algebraic&transdential equations
algebraic&transdential equationsalgebraic&transdential equations
algebraic&transdential equations8laddu8
 
Matlab ploting
Matlab plotingMatlab ploting
Matlab plotingAmeen San
 
Matlab on basic mathematics
Matlab on basic mathematicsMatlab on basic mathematics
Matlab on basic mathematicsmonauweralam1
 
Complex Variable & Numerical Method
Complex Variable & Numerical MethodComplex Variable & Numerical Method
Complex Variable & Numerical MethodNeel Patel
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab sessionDr. Krishna Mohbey
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introductionideas2ignite
 
Matlab Functions
Matlab FunctionsMatlab Functions
Matlab FunctionsUmer Azeem
 
An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersMurshida ck
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applicationsJsaddam Hussain
 

La actualidad más candente (20)

Job sequencing with deadline
Job sequencing with deadlineJob sequencing with deadline
Job sequencing with deadline
 
Combinatorics
CombinatoricsCombinatorics
Combinatorics
 
Linked list
Linked listLinked list
Linked list
 
Importance of matlab
Importance of matlabImportance of matlab
Importance of matlab
 
Matrix operations in MATLAB
Matrix operations in MATLABMatrix operations in MATLAB
Matrix operations in MATLAB
 
PROLOG: Database Manipulation In Prolog
PROLOG: Database Manipulation In PrologPROLOG: Database Manipulation In Prolog
PROLOG: Database Manipulation In Prolog
 
Backtracking
BacktrackingBacktracking
Backtracking
 
MATLAB INTRODUCTION
MATLAB INTRODUCTIONMATLAB INTRODUCTION
MATLAB INTRODUCTION
 
MATLAB Programming
MATLAB Programming MATLAB Programming
MATLAB Programming
 
algebraic&transdential equations
algebraic&transdential equationsalgebraic&transdential equations
algebraic&transdential equations
 
Matlab ploting
Matlab plotingMatlab ploting
Matlab ploting
 
Matlab on basic mathematics
Matlab on basic mathematicsMatlab on basic mathematics
Matlab on basic mathematics
 
Complex Variable & Numerical Method
Complex Variable & Numerical MethodComplex Variable & Numerical Method
Complex Variable & Numerical Method
 
Graph Theory: Trees
Graph Theory: TreesGraph Theory: Trees
Graph Theory: Trees
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab session
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introduction
 
Matlab Functions
Matlab FunctionsMatlab Functions
Matlab Functions
 
An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginners
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
 

Similar a Matlab1

MATLAB-Introd.ppt
MATLAB-Introd.pptMATLAB-Introd.ppt
MATLAB-Introd.pptkebeAman
 
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 projectsMukesh Kumar
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabBilawalBaloch1
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMohd Esa
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functionsjoellivz
 
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.docxgilpinleeanna
 
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 simulinkreddyprasad reddyvari
 
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).docxagnesdcarey33086
 
Matlab ch1 intro
Matlab ch1 introMatlab ch1 intro
Matlab ch1 introRagu Nathan
 
COMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptxCOMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptximman gwu
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentationManchireddy Reddy
 
Introduction to Matlab.pdf
Introduction to Matlab.pdfIntroduction to Matlab.pdf
Introduction to Matlab.pdfssuser43b38e
 
INTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxINTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxDevaraj Chilakala
 
Python High Level Functions_Ch 11.ppt
Python High Level Functions_Ch 11.pptPython High Level Functions_Ch 11.ppt
Python High Level Functions_Ch 11.pptAnishaJ7
 

Similar a Matlab1 (20)

MATLAB-Introd.ppt
MATLAB-Introd.pptMATLAB-Introd.ppt
MATLAB-Introd.ppt
 
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
 
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
 
Introduction to Matlab.pdf
Introduction to Matlab.pdfIntroduction to Matlab.pdf
Introduction to Matlab.pdf
 
INTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxINTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptx
 
Python High Level Functions_Ch 11.ppt
Python High Level Functions_Ch 11.pptPython High Level Functions_Ch 11.ppt
Python High Level Functions_Ch 11.ppt
 

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.