1 / 21

Differential Equations

Math Review with Matlab:. Differential Equations. Finding Solutions to Differential Equations. S. Awad, Ph.D. M. Corless, M.S.E.E. D. Cinpinski E.C.E. Department University of Michigan-Dearborn. Finding Solutions to Differential Equations. Solving a First Order Differential Equation

shood
Download Presentation

Differential Equations

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Math Review with Matlab: Differential Equations Finding Solutions to Differential Equations S. Awad, Ph.D. M. Corless, M.S.E.E. D. Cinpinski E.C.E. Department University of Michigan-Dearborn

  2. Finding Solutions to Differential Equations • Solving a First Order Differential Equation • Solving a Second Order Differential Equation • Solving Simultaneous Differential Equations • Solving Nonlinear Differential Equations • Numerical Solution of a Differential Equation • Using the ODE45 Solver

  3. Solving a 1st Order DE • The Matlab command used to solve differential equations is dsolve • Consider the differential equation: • The general solution is given by: • Verify the solution using dsolve command

  4. Solving a DifferentialEquation in Matlab » syms y t » ys=dsolve('Dy+2*y=12') ys = 6+exp(-2*t)*C1 • C1 is a constant which is specified by way of the initial condition • Dy means dy/dt and D2y means d2y/dt2 etc

  5. Verify Results • Verify results given y(0) = 9 » ys=dsolve('Dy+2*y=12','y(0)=9') ys = 6+3*exp(-2*t)

  6. Solving a 2nd Order DE » syms c y » ys=dsolve('D2y=-c^2*y') ys = C1*sin(c*t)+C2*cos(c*t) • Find the general solution of:

  7. Solving SimultaneousDifferential Equations Example • Solve the following set of differential equations: • Syntax for solving simultaneous differential equations is: dsolve('equ1', 'equ2',…)

  8. General Solution • Given the equations: • The general solution is given by:

  9. Matlab Verification • Given the equations: • General solution is: » syms x y t » [x,y]=dsolve('Dx=3*x+4*y','Dy=-4*x+3*y') x = exp(3*t)*(cos(4*t)*C1+sin(4*t)*C2) y = -exp(3*t)*(sin(4*t)*C1-cos(4*t)*C2)

  10. Initial Conditions • Solve the previous system with the initial conditions: » [x,y]=dsolve('Dx=3*x+4*y','Dy=-4*x+3*y', 'y(0)=1','x(0)=0') x = exp(3*t)*sin(4*t) y = exp(3*t)*cos(4*t)

  11. Non-Linear Differential Equation Example • Solve the differential equation: • Subject to initial condition: » syms y t » y=dsolve('Dy=4-y^2','y(0)=1') » y=simplify(y) y = 2*(3*exp(4*t)-1)/(1+3*exp(4*t))

  12. Specifying the Independent Parameter of a Differential Equation • If another independent variable, other than t, is used, it must be introduced in the dsolve command • Solve the differential equation: » y=dsolve('Dy+2*y=12','x') y = 6+exp(-2*x)*C1

  13. Numerical Solution Example • Not all non-linear differential equations have a closed form solution, but a numerical solution can be found • Solve the differential equation: • Subject to initial conditions: • No closed form solution exists • Use the ode45 command to get a numerical solution

  14. Rewrite Differential Equation • Rewrite in the following form

  15. Create a New Function • Create a Matlab function evalxdot to evaluate and numerically in terms of x1 and x2. function xdot=evalxdot(t,x) %x=[x1, x2] %xdot=[dx1/dt, dx2/dt]; xdot=[x(2); -9*sin(x(1))];

  16. ODE45 • ODE45 is used to solve non-stiff differential equations • [T,Y] = ODE45('F',TSPAN,Y0) T = Time vector Y = Output corresponding to time vector F = Function name TSPAN = Simulation duration Y0 = Initial conditions • If the left hand side [T,Y]of the output arguments is omitted,Matlab solves it and plots it

  17. Returning t, y and dy/dt • Run the solver with the input and output arguments specified » [t,y]=ode45('evalxdot',10,[1 0]); » plot(t,y) » xlabel('Time (sec)'); » ylabel('Amplitude'); » title('Numerical Solution'); » legend('Y','dY/dt')

  18. Plot of Solution

  19. Omit Output Arguments • We can run the solver again without output arguments • Omitting the output arguments causes Matlab to plot the results » ode45('evalxdot',10,[1 0]); » xlabel('Time (sec)'); » ylabel('Amplitude'); » title('Numerical Solution'); » legend('Y','dY/dt')

  20. Plot of Results

  21. Summary • The symbolic toolbox can be used to find the closed form solutions for differential equations where they exist • The symbolic toolbox can be simultaneously solve a system of differential equations • Other Matlab commands can be used to numerically solve systems of differential equations if closed forms do not exist

More Related