Professional Documents
Culture Documents
Intro Matla Blins y Scal Code
Intro Matla Blins y Scal Code
violeta@mit.edu http://web.mit.edu/violeta/www
IAP 2007
Topics
MATLAB Interface and Basics Calculus, Linear Algebra, ODEs Graphics and Visualization Basic Programming Programming Practice Statistics and Data Analysis
IAP 2007
Resources
Class materials
http://web.mit.edu/acmath/matlab/IAP2007 Previous session: InterfaceBasics <.zip, .tar> This session: LinsysCalcODE <.zip, .tar>
IAP 2007
MATLAB + Mathematics
+ Matrices and Linear Algebra
+ Solving Linear Systems of Equations + Inverses and Determinants Eigenvalues
+ Differential Equations
+ Initial Value Problems for ODEs and DAEs
IAP 2007 Introduction to MATLAB: Calculus, Linear Algebra, Differential Equations
IAP 2007
Integration
n +1
x+C
Analytical solution
IAP 2007
Differentiation
Polynomial differentiation
d ( P1 x n + ... + Pn x + C ) = p1 x n !1 + ... + pn dx
IAP 2007
Differential Equations
y ' = f (t , y)
M (t , y ) y ' = f (t , y )
IAP 2007
Syntax
>> [T,Y] = solver(odefun,tspan,Y0) solver: ode45, ode23, etc. odefun: function handle tspan: interval of integration vector Y0: vector of initial conditions [T, Y]: numerical solution in two vectors
IAP 2007
! ! F = ma
dv ( t ) m = mg ! kv 2 ( t ) dt
dv ( t ) k 2 = g ! v (t ) dt m
Theoretical example courtesy of Ms. Shannon Cheng, MIT Department of Aeronautics & Astronautics.
IAP 2007
Problem:
dv ( t ) k 2 = g ! v (t ) dt m
PDE Solver
! 2V ! 2V + 2 =0 2 !x !y
IAP 2007
Useful Functions
IAP 2007
Matrix form: Ax = b
! a11 ... a1n $ ! x1 $ ! b1 $ # ... ... ... & # ... & = # ... & # &# & # & # " an1 ... amn & %# " xm & % # "bm & %
IAP 2007 Introduction to MATLAB: Calculus, Linear Algebra, Differential Equations
Define matrix A >> A = [a11 a12 a1m a21 a22 a2m an1 an2 anm] Define vector b >> b = [b1; b2; bm] Compute vector x >> x = A \ b
IAP 2007 Introduction to MATLAB: Calculus, Linear Algebra, Differential Equations
State Equation
y ' = f (t , y )
x = Ax
Identify initial conditions .. x ( 0 ) Find the state equation . x = Ax Find eigenvalues & eigenvectors !i , " i The general solution is . x t = Solve for ai . a = [ v1
()
! aiv ie
i
"i t
v2
... vn ] x ( 0 )
!1
IAP 2007
i4
L4 2H
State equation
$ '2 & ! v1 $ & # & = Ax i '3 & " 4 % & %
i4 ( 0 ) = 1
! dv1 $ ! 1 ' ! x1 ' $ # dt & # 2 x =# &=# &=# " x2 ' % # di4 & # 1 # " dt & % # " 2
IAP 2007
Theoretical example courtesy of Prof. Stephen Hall, MIT Department of Aeronautics & Astronautics. Introduction to MATLAB: Calculus, Linear Algebra, Differential Equations
i4
L4 2H
x = Ax Av i = !iv i
&1
()
()
Analytical solution
x t = a1v 1e
()
!1t
+ a2v 2e
!2t
()
()
IAP 2007
() ()
>> A = [a11 a12; a21 a22] >> x0 = [v1,0; i4,0] >> [V, L] = eig(A) >> = diag(L) >> a = V \ x0 >> v1 = a1*V11*exp(1*t) + a2*V12*exp(2*t) i4 = a1*V21*exp(1*t) + a2*V22*exp(2*t)
Av i = !i"i
% a =# $v 1 v 2 & x 0 !t x t = ( aiv ie i
'1
()
IAP 2007
IAP 2007
Complex Eigenvalues
Eulers Formula
e ! + " j = e ! cos " + j sin "
()
Convolution
Definition
g (t ) ! u (t ) =
"$
% g (t " # )u (# ) d#
y(t) = u(t)*g(t)
IAP 2007
Polynomial Convolution
Polynomials:
x(s) = s2 + 2s + 5; y(s) = 2s2 + s + 3 >> x = [1 2 5]; y = [2 1 3]
IAP 2007
Example: RC Circuit
1 + u(t) _ 2 + 1F y(t) _
Input:
e! t , t " 0 u (t ) = 0, t < 0
System response:
Theoretical example courtesy of Prof. Stephen Hall, MIT Department of Aeronautics & Astronautics. IAP 2007 Introduction to MATLAB: Calculus, Linear Algebra, Differential Equations
IAP 2007
t = [0 : dt : tmax] nt = length(t) g = exp(*t) u = exp(*t) y = conv(g, u)*dt y = y(1 : nt) plot(t, u, b-, t, g, g-, t, y, r-)
IAP 2007
IAP 2007