Introduction to MATLABvibes.uml.edu/modules/PDF/COMP_MOD/INTRO_MATLAB.pdf · Introduction to...
Transcript of Introduction to MATLABvibes.uml.edu/modules/PDF/COMP_MOD/INTRO_MATLAB.pdf · Introduction to...
Introduction to MATLAB
Timothy FicarraNSF GK-12 Fellow
Vibes and Waves in ActionComputer Architecture and Network Systems Lab
University of Massachusetts Lowell
Presented to two Senior Physics Classes, Lowell High School11/3/09
12/16/09
What is MATLAB?
MATLAB is a software product.Useful for– 2D-3D plotting – Computation/calculation– Prototyping
(prototype: an experimental model)– Creating models and simulations– Algorithms
(algorithm: step-by-step procedure to solve a problem)Makes it easier when calculations are on big sets of numbers.Launch Matlab– Q:/MATLAB/R2009a
MATLAB DesktopCommand Window: a big calculator
Workspace
Command History
Details
CurrentDirectory
Matlab CalculationsBasic operations: +,-,/,*Try:5+46-5+4*3 Question: Does Matlab follow the order of operations?sqrt(121)semicolon (;) stops the output displaysqrt(10); -> will not display the result.abs(-10)2^22^3
Question: What operation is ^ ?
Variables/Numbers
Variable is a place holder for numbers.Example :a = 20.2b = 10.13*a+bList– Matlab allows us to perform operations on list of
numbers. List of number -> an array
– One way to create a list of numbers:T=begin:interval:endExp: t=300:10:350. Question: What are the values of t?
– operations on listExp: 2*T , T+T
Generating Plots
Plot two variables– x=1:1:8; y=50:5:85;– plot(x,y)
Add labels and titles– xlabel(‘Time of the day (hr)’)– ylabel(‘Temperature (f)’)– title(‘Change of temperature during a day’)
Formulas
Formulas are equations. They express information symbolically. Symbols of a formula are variables, which represent an entity.Exp: F=maF: force, m: mass, a: acceleration
Formula Exercise
Celsius/Fahrenheit conversion formula:Celsius = (5/9)*(Fahrenheit – 32)
Exercise:Can you plot the Celsius-Fahrenheit for the
range of -30 to 120 Fahrenheit degrees?
ArraysArray is a space holder for a set of variables.Arrays can be multi-dimensional.– 2D array is a matrix.
Our focus today is on 1D arrays– To enter values for an array:
X=[1,4,2,7,10,3,4,]– You can apply operations on arrays.
Y=X*2– To reach to an element of array
X(N), where N is element index numberexp: X(4)
Measures of Central Tendency
X=[1,4,2,7,10,3,4,]Our sorted data : 1 2 3 4 4 7 10
Matlab functions:– mean(X)– median(X)– mode(X)– range(X)
Total rain fall in Grand Canyoninches
– 1999 16.5 – 2000 15.2– 2001 16.8– 2002 4.2– 2003 17.0– 2004 15.9– 2005 17.1– 2006 14.9– 2007 17.1
2008 16 5
Create an array for rain fall, and plot it. Compute mean, median, mode, range
Outlier?
To eliminate the outlier:X(4)=[ ]X = 16.5 15.2 16.8 17.0 15.9 17.1
14.917.1 16.5
mean(X) = 16.25mode(X) = 16.5median(X) = 16.5range(X) = 2.2