Matlab PPT 2
Matlab PPT 2
MathWork
s®
Introduction
What is MATLAB ?
(MATrix LABoratory)
MATLAB is a powerful computer software application
program for solving engineering problems. It is applicable
for all engineering desciplines and many natural sciences as
well.
MATLAB handles numerical calculations and high quality
graphics , provides a convenient interface to built in state of
the art subroutine libraries, and incorporates a high level
programming language.
+ Addition 6+5=11
- Subtraction 6.7-2=4.7
* Multiplication 4*5=20
^ Exponent 4^2=16(42)
Examples-
Ques. Add , multiply, divide, and squaring the given no. 5 and 6.
order of precedence is: Parenthesis , Exponents, Multiplication and division,
Variables is a name made up of a letter or a combination of several letters and numbers and
Pi 3.14159 (number π)
Inf ∞ (infinity)
1.VECTORS(1 D arrays)-
Vector is one dimension array. It contains only a row or a
column. If a vector is a row vector and it has n elements then
size of this vector is denoted by 1Xn. On the other hand if it is
a column vector and it has n elements then the size of this
vector is denoted by nX1.
Row vector:
V= [1,2,3,4,5,……..n]
Column vector:
V= [1;2;3;4;5;…….n]
(a)Representation of polynomials:
In MATLAB, polynomials are represented by a row vector of its
coefficients. If the polynomial has degree n,then the
corresponding representing vector has length n+1 and contains
the coefficients associated with decreasing powers from left to
right. For example: Y(x)=3x2+2x+1
>>y=[3 2 1]
And >>z=[3 0 -1 4] represents polynomial z=3x2-x+4
(d)symbolic math:
We assign a MATLAB variable name to a string or characters that
define the mathematically function that we want to manipulate in
some manner. The key function in MATLAB to create a symbolic
representation of data is sym() and syms.
>>A=sym(‘x’)
>>syms a b c
If symbolic variables variables are defined we can construct
symbolic expressions using arithmetic operators.
>>f=5.1*x^3+a*x^2+b*x+c
We can also access standard built in MATLAB functions such as
trigonometric functions, matrix functions,exponentials etc.
>>g=sin(x)*exp(-x)-sinh(x)*x^2
>>f*g+a*c+1
(e)differentiation and integration:
Let x= sin(t) in MATLAB is
>>syms t;
>>x= sin(t);
>>diff(x)
>>diff(x,2)
For integration
>>int(x)
>>int(x,t)
>>int(x,a,b)
(e)Multiple plots:
There are 3 different methods to draw multiple plots:
1.using plot function ->>plot(x1,y1,x2,y2,x3,y3)
2.using hold function->>hold on
3.using line function->>line(xdata, ydata)
(f)subplots:
>>subplot(2, 1, 1)
>>plot (y)
>>subplot(2, 1, 2)
>>plot(m)
(f)bar function:
>>bar(y)
>>bar(x, y)
(g)pie plots
(h)3D plots
:
(i)Mesh and surface plots:
1.creating a x-y grid: >>[X Y]=meshgrid(x, y)
>>[X Y]=meshgrid(xstart:xinc:xend,
ystart:yinc:yend)
2.calculating the value of Z: >>z=f(x, y)
3.creating mesh and surface plots:
>>mesh(x, y, z)
Simulink
Simulink derived from the word simulation and link.
Simulink is available in the form of a toolbox and is an
integral part of MATLAB. Simulink is a software package
for modeling, simulating, and analyzing dynamical systems.
Key features of simulink:
(1)graphical editor for building and managing hierarchical block
diagram.
(2)libraries of predefines blocks for modeling continuous time and
discrete time systems.
(3) scopes and data display for viewing simulation results.
(4)project and data management tools for managing data files and
data.
(5) legacy tools for importing C and C++ code into modles.
Starting up simulink:
(a) by typing simulink at the MATLAB and then enter
>>simulink
(b) by clicking on the icon from toolbar menu
(c)selecting simulink library browser from the pop up menu
obtain by clicking the start menu.
Let us take a simple example to create simulink model, to plot a
sinusoidal waveform:
Step 1-open a new model file
(a)by clicking on the new model icon from the toolbar of simulink library
browser
THANK YOU