 Mat lab is very useful in design field now a days it is
widely using software
 It has so many predefined functions
 It is space sensitive and case sensitive
 It is used in rocket launching and designing of
mechanical parts
Some Mat Lab development windows
 Command Window : where you enter commands
 Command History : It shows the previously entered
commands
 Editor : Here we edit programs
COMMANDS
 CLEAR : remove items from workspace
 WHO: list variables in workspace
 QUIT: close matlab
Math Functions
 Abs(x)=mod x
 Sqrt(x)=root x
 Round(x)=rounds to nearest
integer
 Fix(x)=round to nearest integer
towards zero
 Ceil(x)=nearest to infinite
 Ceil(x)=nearest to –ve infinite
 Rem(x,y)=gives remainder
 Exp(x)=e^x
 Log(x)=log x base e
 Sin(x)
 Cos(x)
 Tan(x)
 sinh(x)
 Cosh(x)
 Tanh(x)
Matrix entering in mat
 A=[1 2 3;2 3 4]
 Output we get here is
1 2 3
2 3 4
Colon for matrix
A(:,n) = selects all row elements in nth column of A
A(n,:) = selects all column elements in nth row of A
A(:,m:n)=selects all rows b/w columns m & n
A(m:n,:) = selects all columns b/w rows m &n
A(m:n,p:q) = selects elements in rows b/w m & n and
colmns b/w p &q
Isequal(a,b) = if element in a=b returns 1 otherwise 0
Ismember(a,b) = if a element in b returns 1 otherwise 0
Some more commands
 Magic(x)
 Sum(x)
 X’
 Diag(x)
 Fliplr(x)
 Flipud(x)
 Size(x)
 X(i,j)=n
 Length(a)
 Mean(A)
 Max(a)
 [d,n]=max(a)
 Min(a)
 Sort(a)
 Median(a)
 Std(a)
 Rand
 Rand(m,n)
Some functions
1 . Syms x
f = inline (‘x^2+2x+1)
2 . Syms (u,v)
simplify((u^3-v^3)/(u-v))
3. Syms a
syms b
syms c
syms x
solve(‘a*x^2-b*x+c)
Solving polynomial
 5*s^5+7*s^4+2*s^3+6*s+1
 To enter into the mat lab software for working
 x=[5 7 0 2 6 1]
 At the value of s=2
 Enter
 X=polyval([x],2)
 X=278
Muliplying two polynomials
 Here we write
 X=[1 2 3]
 Y=[3 4 5]
 Z =conv(x,y)
 Z=2 11 29 35
Statements
 If/elseif/else
 For loop
 While loop
Reading & writing diff files
For reading text files
X = dimread(‘abc.txt’,’,’)
For writing text files
X=[1 2 3 5 7 ]
dlmwrite(‘uvw.txt’,x);
For xls files enter xls in place dlm
Reading image files
F=uigetfile(‘*.m,*.bmp,*.gif,*.jpg’,’xxxxx’)
For plotting graphs
Plot(x,y)

mat lab introduction and basics to learn

  • 2.
     Mat labis very useful in design field now a days it is widely using software  It has so many predefined functions  It is space sensitive and case sensitive  It is used in rocket launching and designing of mechanical parts
  • 3.
    Some Mat Labdevelopment windows  Command Window : where you enter commands  Command History : It shows the previously entered commands  Editor : Here we edit programs
  • 4.
    COMMANDS  CLEAR :remove items from workspace  WHO: list variables in workspace  QUIT: close matlab
  • 5.
    Math Functions  Abs(x)=modx  Sqrt(x)=root x  Round(x)=rounds to nearest integer  Fix(x)=round to nearest integer towards zero  Ceil(x)=nearest to infinite  Ceil(x)=nearest to –ve infinite  Rem(x,y)=gives remainder  Exp(x)=e^x  Log(x)=log x base e  Sin(x)  Cos(x)  Tan(x)  sinh(x)  Cosh(x)  Tanh(x)
  • 6.
    Matrix entering inmat  A=[1 2 3;2 3 4]  Output we get here is 1 2 3 2 3 4
  • 7.
    Colon for matrix A(:,n)= selects all row elements in nth column of A A(n,:) = selects all column elements in nth row of A A(:,m:n)=selects all rows b/w columns m & n A(m:n,:) = selects all columns b/w rows m &n A(m:n,p:q) = selects elements in rows b/w m & n and colmns b/w p &q Isequal(a,b) = if element in a=b returns 1 otherwise 0 Ismember(a,b) = if a element in b returns 1 otherwise 0
  • 8.
    Some more commands Magic(x)  Sum(x)  X’  Diag(x)  Fliplr(x)  Flipud(x)  Size(x)  X(i,j)=n  Length(a)  Mean(A)  Max(a)  [d,n]=max(a)  Min(a)  Sort(a)  Median(a)  Std(a)  Rand  Rand(m,n)
  • 9.
    Some functions 1 .Syms x f = inline (‘x^2+2x+1) 2 . Syms (u,v) simplify((u^3-v^3)/(u-v)) 3. Syms a syms b syms c syms x solve(‘a*x^2-b*x+c)
  • 10.
    Solving polynomial  5*s^5+7*s^4+2*s^3+6*s+1 To enter into the mat lab software for working  x=[5 7 0 2 6 1]  At the value of s=2  Enter  X=polyval([x],2)  X=278
  • 11.
    Muliplying two polynomials Here we write  X=[1 2 3]  Y=[3 4 5]  Z =conv(x,y)  Z=2 11 29 35
  • 12.
  • 13.
    Reading & writingdiff files For reading text files X = dimread(‘abc.txt’,’,’) For writing text files X=[1 2 3 5 7 ] dlmwrite(‘uvw.txt’,x); For xls files enter xls in place dlm Reading image files F=uigetfile(‘*.m,*.bmp,*.gif,*.jpg’,’xxxxx’) For plotting graphs Plot(x,y)