Anda di halaman 1dari 26

By Vatsal Sanjay

MIESS
What, why and Introduction Self help
how and basic assignments
• What is MATLAB? commands • Questions to try on
• Why should we • Direct application own
know MATLAB? in command • What to do next?
• How to learn window
MATLAB • Code writing in
the “EDITOR”
• Inbuilt commands
and functions
HIGH PERFORMANCE
LANGUAGE

COMPUTATIONAL
SOFTWARE (A
MATrix DATA EXTRACTION
CALCULATOR)
LABoratory

GRAPHICS
 MATLAB stores all data in
form of matrix.

 If I enter a number say


2308. IT IS ACTUALLY A
MATRIX of index 1 x 1....
 However a 1 x 1 matrix
will behave just like a
scalar. If you write 2308*A
where A can be a 3x3
MATRIX or any matrix for
that matter.
 Especially for Mechanical
Engineering related works,  I think you have spent a full
what you need is not hardcore semester knowing about the
coding but the ability to write characteristics and clumsiness
programs which are concise of these languages.
and effective in data
extraction, plotting , creating
graphical interface (animation
and simulations).  No offence to those who love
C++ or C. No doubt they are
 NUMEROUS TOOLBARS TO MAKE the basic languages with higher
LIFE EASY speed but lack certain factors
which are the plus points of
 Less worries about the Syntax. MATLAB.
 USER FRIENDLY

MATLAB C++/other languages


 Work space- Where all your
“Variables” are stored
 Command Window- Here
you can directly execute
commands. It is like a
POWERFUL CALCULATOR.
 Command history – it is like
your log book.
 EDITOR- if you have to
execute a set of commands;
instead of writing commands
separately, you can use
editor to write, debug and
run them. – “%” Is used to
add comments
5+2 5*2 3+2*(4+3)

2.545*2.308/1.116 6.3-5.445 3.6^2

sqrt(5) cos(pi) pi
Variables
• NOMENCLATURE FOLLOWS SAME RULES AS
C++

NO SPACE
• Use no space in names.

CASE SENSITIVE
• A is not same as a..

Program file execution


• MATLAB COMPILER READS THE FILE LINE
BY LINE...
• Clears the command window.
clc

• Cleans off the work space


clear/clear
all

• Closes any graphical interface or


windows other than your main window,
close/close
all like “figure” which might be opened
 Standard operations are the
simple linear algebra operations
on matrices
 AssignA as a 200x200 magic square. Take out
row 55 to 60 and column 23 to 28 as a 6x6
matrix and assign it as matrix B. Form a
matrix C equal to the standard matrix
squared of matrix B and a matrix D as the
element wise square of the matrix B.
(a) Multiply transpose of C to D and add B to
get a matrix E.
(b)Find eigen values of matrix E and its (c)
determinant and further its (d) inverse.
MATLAB indices start with
“1” not “0”...

To call an element of the


matrix, you can use
subscripts or indices.
 Every time you press the “enter” key after
writing a command, MATLAB prints the
results in command window... You can skip
this by using a semicolon. MATLAB does the
computation but doesn’t display the result.
 Notethat inv(A)*B
and A\B are the
same if A is a
square matrix.
A\B solves the
equation using
GAUSS elimination
method.
 X=
linspace(0,2*pi,4);
 Y=(sin(X)).^2;
 plot (X,Y)
 WELL! that didn’t
really go as
expected... Any
guess what this
might be the case?
 X=
linspace(0,2*pi,1000
);
 Y= (sin(X)).^2;
 Plot(X,Y);
 If you know the
interval between
consecutive x
values; instead of
linspace you can use
simple vector X and Y must have the same
initialisation that is dimension for plotting
X= 0:0.0001:2*pi;
 clc
clear all
x=5;
format long
For n=1:1:50
x=sqrt(1+x);
plot (n,x,'d')
hold on
THERE IS ANOTHER WAY TO SOLVE THIS... In
end command window type
hold on syms x
plot([0,0],[0,5],'k- X= solve(x-sqrt(1+x)==0,x)
',[0,10],[0,0],'k-') In this case syms represents symbolic
representation. Answer obtained this way are
disp (x)
symbols and are usually in fraction form
P=[1 -1 -1];
R=roots(P)
squaring adds an extra root
help is the most useful command if you
want to learn MATLAB.

• Suppose if you want to know what does the word


“sin” do in MATLAB; enter help sin in the command
window.

Along with the description about the


asked work, it also lists related
commands alongside
 Apart from using the help command you can always
rely on google.
 No book or course can make you proficient with
MATLAB or anything for that matter unless you
yourself practice it and explore things.
 So explore MATLAB... Try solving your class problems
using MATLAB. You got a question, an idea.. Simply
log on to the MATLAB window and try it out. For eg if
you learn say gauss elimination method to solve set
of linear equations, come back home; open MATLAB
and see how you can write a code for that.
 www.mathworks.in / in.mathworks.com are be the
places you would like to visit if you have how this is
done type of questions.
 help functional_handle
 help fzero
 help diff
 help gradient
 help integrate
 help ode45
 help contour
 help fit