MATLAB RESOURCES

 


 

A Matlab tutorial from the University of New Hampshire

Getting Started with MATLAB

 

 

 

Quick introduction to MATLAB

 

Defining a Vector

 

>> v = [3  1 1]

v =

     3     1    1

 

Defining Matrices

 

>> A = [ 1 2 3; 3 4 5; 6 7 0]

A =

     1     2     3

     3     4     5

     6     7     0

 

Matrix time a vector

 

>> A*v'

 

ans =

 

     8

    18

    25

Inverse of a Matrix

 

>> inv(A)

 

ans =

 

   -2.1875    1.3125   -0.1250

    1.8750   -1.1250    0.2500

   -0.1875    0.3125   -0.1250

 

Eigenvalues

>> eig(A)

 

ans =

 

   10.4237

   -0.2996

   -5.1241

Eigenvectors

>> [v,e] = eig(A)

 

v =

 

   -0.3504   -0.7526   -0.3044

   -0.6717    0.6497   -0.3788

   -0.6527   -0.1071    0.8740

 

 

e =

 

   10.4237         0         0

         0   -0.2996         0

         0         0   -5.1241

        

Determinant

>> det(A)

 

ans =

 

    16

 

 

Echelon Form ( ROWREDUCE)

>> R = rref(A)

 

R =

 

     1     0     0

     0     1     0

     0     0     1

rrefmovie(A)

 

Characteristic polynomial

>> syms lemda

>> det( A - lemda*eye(3) )

 

ans =

 

55*lemda+5*lemda^2+16-lemda^3

 

 Matrix Exponential

>> exp(A)

 

ans =

 

  1.0e+003 *

 

    0.0027    0.0074    0.0201

    0.0201    0.0546    0.1484

    0.4034    1.0966    0.0010

Solve a Differential Equation

 

Solve   y' - 4 y = 0

 

>> dsolve('Dy - 4*y = 0')

 

ans =

 

C1*exp(4*t)

 

 

System of Differential Equations

 

 

x' = 2 x + 3 y

y'=     x -  2y

x(0)=1

y(0)=1

 

>> sol = dsolve( 'Dx=2*x+3*y','Dy=x-2*y','x(0)=1','y(0)=1')

 

sol =

  

   x:  [1x1  sym]

   y:  [1x1  sym]

 

>> sol.x

 

ans =

 

 (-1/14*7^(1/2)+1/2)*7^(1/2)*exp(7^(1/2)*t)- ........

 

>> t=2.3;

 

>>subs(sol.x)

 

ans =

 

  634.7773