SlideShare a Scribd company logo
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]

More Related Content

What's hot

Arrays Data Structure
Arrays Data StructureArrays Data Structure
Arrays Data Structure
student
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
Damian T. Gordon
 
Operators in python
Operators in pythonOperators in python
Operators in python
eShikshak
 
Arrays and structures
Arrays and structuresArrays and structures
Arrays and structuresMohd Arif
 
NumPy/SciPy Statistics
NumPy/SciPy StatisticsNumPy/SciPy Statistics
NumPy/SciPy Statistics
Enthought, Inc.
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
BilawalBaloch1
 
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Edureka!
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
Apurbo Datta
 
Python NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | EdurekaPython NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | Edureka
Edureka!
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
Mohan Raj
 
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)
PyData
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
moazamali28
 
Queue ppt
Queue pptQueue ppt
Queue ppt
SouravKumar328
 
List in Python
List in PythonList in Python
List in Python
Siddique Ibrahim
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in python
hydpy
 
Array in c programming
Array in c programmingArray in c programming
Array in c programming
Mazharul Islam
 
Strings in python
Strings in pythonStrings in python
Strings in python
Prabhakaran V M
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
Janki Shah
 
Variables & Data Types In Python | Edureka
Variables & Data Types In Python | EdurekaVariables & Data Types In Python | Edureka
Variables & Data Types In Python | Edureka
Edureka!
 

What's hot (20)

Arrays Data Structure
Arrays Data StructureArrays Data Structure
Arrays Data Structure
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
Arrays and structures
Arrays and structuresArrays and structures
Arrays and structures
 
NumPy/SciPy Statistics
NumPy/SciPy StatisticsNumPy/SciPy Statistics
NumPy/SciPy Statistics
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
Python NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | EdurekaPython NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | Edureka
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
List in Python
List in PythonList in Python
List in Python
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in python
 
Array in c programming
Array in c programmingArray in c programming
Array in c programming
 
Linked list
Linked listLinked list
Linked list
 
Strings in python
Strings in pythonStrings in python
Strings in python
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Variables & Data Types In Python | Edureka
Variables & Data Types In Python | EdurekaVariables & Data Types In Python | Edureka
Variables & Data Types In Python | Edureka
 

Similar to Matlab1

MATLAB-Introd.ppt
MATLAB-Introd.pptMATLAB-Introd.ppt
MATLAB-Introd.ppt
kebeAman
 
An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginners
Murshida ck
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
chestialtaff
 
Matlab Basic Tutorial
Matlab Basic TutorialMatlab Basic Tutorial
Matlab Basic Tutorial
Muhammad Rizwan
 
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
Mukesh Kumar
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
Mohd Esa
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
raghav415187
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
joellivz
 
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
 
Importance of matlab
Importance of matlabImportance of matlab
Importance of matlab
krajeshk1980
 
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
reddyprasad 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).docx
agnesdcarey33086
 
Matlab ch1 intro
Matlab ch1 introMatlab ch1 intro
Matlab ch1 intro
Ragu Nathan
 
COMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptxCOMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptx
imman gwu
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
Manchireddy Reddy
 
Introduction to Matlab.pdf
Introduction to Matlab.pdfIntroduction to Matlab.pdf
Introduction to Matlab.pdf
ssuser43b38e
 
INTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxINTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptx
Devaraj Chilakala
 

Similar to Matlab1 (20)

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
 
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
 
Importance of matlab
Importance of matlabImportance of matlab
Importance of 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
 
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
 

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.