120 likes | 298 Views
Mathematical Modeling and Simulation. Differential Equations. Using MATLAB. (Plus Symbolic Mathematics). Prof. Muhammad Saeed. Symbolic Math syms x y z a b ; 1. Expansion: expand((x+a)^3); expand(sin(a+b)); 2. Factorization: factor(a^2-b^2); 3. Series Summation: syms k n;
E N D
Mathematical Modeling and Simulation Differential Equations Using MATLAB (Plus Symbolic Mathematics) Prof. Muhammad Saeed
Symbolic Math • syms x y z a b ; • 1.Expansion: • expand((x+a)^3); expand(sin(a+b)); • 2.Factorization: • factor(a^2-b^2); • 3.Series Summation: • syms k n; • symsum(k,0,10);symsum(k^2,1,4);sysmsum(k,0,n-1) • 4.Substitution: • Expr=x^2+6*x+9; subs(Expr,x,2); subs(Expr,x,a); • 5.Solution of Equations: • solve(‘3*x^3+2*x^2-4*x+12=0’); • solve(3*x^3+2*x^2-4*x+12); • solve(‘sin(2*x)-cos(x)=0’); • 6.Solution of Simultaneous Equations: • eqn1=‘4*x+3*y=5’; eqn2=‘2*x+2*y=-3’; • S=solve(eqn1,eqn2); { S.x, S.y} • S=solve(eqn1,eqn2, …….);
Symbolic Math: • 7.Limit: • limit(sin(x)/x) • f = sin(x)/x; • limit(f); limit(f,a); limit(f, x,a,); limit(f,x,a,’right’); • limit(f,x,a,’left’); • 8.Taylor Series: • f=exp(x); taylor(f, 5); taylor(f, 5,2); • 9.Graph Plot: • ezplot(f, [-3 3]) • 10.Differentiation: • syms x n; • diff(x^n) • diff(‘(sin(x))^2’) • diff(x*sin(x*y), y, 2)
Symbolic Math: • 11. Integration: • syms x y n a b • int(x^n); • int(x^n, n); • int(xy^2,y,0,4); • int(x^3, a,b); • 12.Laplace Transform: • syms s b t w x; • laplace(t^3); • laplace(exp(-b*t)); laplace(exp(a*s)) ; • laplace(sin(w*x),t); laplace(cos(x*w),w,t); • laplace(diff(sym('F(t)')))
Symbolic Math: • 13. Inverse Laplace Transform: • ilaplace(1/s^3); • ilaplace(1/(s+b); • ilaplace(b/(s^2+b^2)); • 14.More to study: • fourier, ifourier, • ztrans, iztrans, • sym, • poly2sym, sym2poly • findsym, • simplify, • collect • See for DE solution using Laplace Transform: DESymb.m
Symbolic Solution of Differential Equations: • ∆ dsolve(‘Dy+2*y = 12’) • ∆ dsolve(‘Dy = sin(a*t)’) • ∆ dsolve(‘D2y = c^2*y’) • ∆ [x, y] = dsolve(‘Dx = 3*x+4*y’, ‘Dy = -4*x+3*y’) • ∆ dsolve(‘Dy = sin(a*t)’, ‘y(0) = 0’) ; { ‘y(0) = c’ } • ∆ dsolve(‘D2y = c^2*y’,’y(0) = 1’,’Dy(0) = 0’) • ∆ [x, y] = dsolve(‘Dx = 3*x+4*y’, ‘Dy = -4*x+3*y’,’x(0) = 0’,’y(0) = 1’) • ∆ dsolve(‘D2y+9*sin(y) = 0’,’y(0) = 0’,’y(L) = 0’)
Numeric Solution of Differential Equations: • 1. Euler’s Method. Example: DEEulersMethod.m • 2. MATLAB ODE Solvers
Numeric Solution of Differential Equations: • a) DE’s Of Order 1: • [t, y]=solver(‘func’,[ti tj], y(i)) • function ydot=funcName(t,y) • ydot= f(y,t)………. ; • end • ODE’s: • b) DE’s Of Order 2: • [t, x]=solver(‘function’,[ti, tj],[y(i), y(j)]) • function xdot=funcName(t,x) • xdot(1)=x(2) • xdot(2)= func( x(1), x(2), t ) • xdot=[xdot(1);xdot(2)]; • end; • ODE: ,van der Pol Eqn.
Numeric Solution of Differential Equations: Examples: I. DE’s Of Order 1 function ydot = DEorder1_01(t,y) ydot = sin(t); end [t,y] = ode23(‘DEorder1_01’, [0, 4*pi], 0); Analytic Solution ‘ y= 1-cos(t) ‘
Numeric Solution of Differential Equations: Examples: 2. DE’s Of Order 2 ( van der Pol Eqn. ) function ydot = vdpol(t,y) mu = 2; ydot(1) = y(2); ydot(2) = mu*(1-y(1)^2)*y(2) – y(1); ydot = [ydot(1); ydot(2)]; end [t,y] = ode45(‘vdpol’, [0, 20],[2; 0]);
Numeric Solution of Differential Equations: Examples: 2. DE’s Of Order 2 ( van der Pol Eqn. ) function ydot = vdpol2((t,y,mu) ydot(1) = y(2); ydot(2) = mu*(1-y(1)^2)*y(2) – y(1); ydot = [ydot(1); ydot(2)] end options=odeset(‘Refine’,4); [t,y] = ode45(‘vdpol’, [0, 20], [2; 0], options, 2);