solve a single differential equation

Upload: koko-bdh

Post on 07-Aug-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/20/2019 Solve a Single Differential Equation

    1/2

    Solve a Single Differential Equation

    Use dsolve to compute symbolic solutions to ordinary differential equations. You can specify the equations as

    symbolic expressions containing dif  or as strings with the letter D to indicate differentiation.

    Note:  Because D indicates differentiation, the names of symbolic variables must not contain D.

    Before using dsolve, create the symbolic function for which you want to solve an ordinary differential equation.

    Use sym or syms to create a symbolic function. For example, create a functiony(x):

    syms y(x)

    For details, see reate !ymbolic Functions.

    "o specify initial or boundary conditions, use additional equations. #f you do not specify initial or boundary

    conditions, the solutions will contain integration constants, such as C1, C2, and so on.

    "he output from dsolve parallels the output from solve. "hat is, you can:

    • all dsolve with the number of output variables equal to the number of dependent variables.

    • $lace the output in a structure whose fields contain the solutions of the differential equations.

    First-Order Linear ODE

    !uppose you want to solve the equation y'(t) = t*y. First, create the symbolic function y(t):

    syms y(t)

    %ow use dsolve to solve the equation:

    y(t) = dsolve(dif(y,t) == t*y)

    y(t) =

    C2*exp(t^2/2)

    y(t) = C2*exp(t^2/2) is a solution to the equation for any constant C2.

    !olve the same ordinary differential equation, but now specify the initial condition y(0) = 2:

    syms y(t)

    y(t) = dsolve(dif(y,t) == t*y, y(0) == 2)

    y(t) =

    2*exp(t^2/2)

    Nonlinear ODE

    %onlinear equations can have multiple solutions, even if you specify initial conditions. For example, solve thisequation:

    syms x(t)

    x(t) = dsolve((dif(x,t) + x)^2 == 1, x(0) == 0)

    results in

    x(t) =

     exp(-t) - 1

     1 - exp(-t)

    Second-Order ODE with Initial Conditions

    !olve this second&order differential equation with two initial conditions. 'ne initial condition is aderivative y'(x) at x = 0. "o be able to specify this initial condition, create an additional symbolic function Dy =

    http://www.mathworks.com/help/symbolic/dsolve.htmlhttp://www.mathworks.com/help/symbolic/dsolve.htmlhttp://www.mathworks.com/help/symbolic/diff.htmlhttp://www.mathworks.com/help/symbolic/diff.htmlhttp://www.mathworks.com/help/symbolic/diff.htmlhttp://www.mathworks.com/help/symbolic/create-symbolic-functions.htmlhttp://www.mathworks.com/help/symbolic/diff.htmlhttp://www.mathworks.com/help/symbolic/create-symbolic-functions.htmlhttp://www.mathworks.com/help/symbolic/dsolve.html

  • 8/20/2019 Solve a Single Differential Equation

    2/2

    dif(y). (You also can use any valid function name instead of Dy.) "hen Dy(0) = 0 specifies that Dy = 0 at x

    = 0.

    syms y(x)

    Dy = dif(y);

    y(x) = dsolve(dif(y, x, x) == cos(2*x) - y, y(0) == 1, Dy(0) == 0);

    y(x) = simpliy(y)

    y(x) =

    1 - (!*si"(x/2)^#)/$

    Third-Order ODE

    !olve this third&order ordinary differential equation:

    d$%dx

    $=u

    u(0)=1, u′(0)=1, u′′(0)=π ,

    Because the initial conditions contain the first& and the second&order derivatives, create two additional symbolic

    functions, Dy and D2y to specify these initial conditions:

    syms %(x)

    D% = dif(%, x);

    D2% = dif(%, x, 2);

    %(x) = dsolve(dif(%, x, $) == %, %(0) == 1, D%(0) == -1, D2%(0) == pi)

    %(x) =

     

    (pi*exp(x))/$ - exp(-x/2)*cos(($^(1/2)*x)/2)*(pi/$ - 1) -

    ($^(1/2)*exp(-x/2)*si"(($ (̂1/2)*x)/2)*(pi + 1))/$

    More ODE Ea!"les

    "his table shows examples of differential equations and their !ymbolic *ath "oolbox+ syntax. "he last example

    is the iry differential equation, whose solution is called the iry function.

    Differential Equation MATLAB® Command

    dydt +# y (t )=et 

     y(0) = 1

    syms y(t)

    dsolve(dif(y) + #*y == exp(-t), y(0) == 1)

    2 x2 y′′ + 3 xy′  y = 0

    ( ′ = d !dx)

    syms y(x)

    dsolve(2*x^2*dif(y, 2) + $*x*dif(y) - y == 0)

    d2ydx2= xy ( x ) y (0)=0,  y ($)=

    1π K 

    1!$(2"$)

    (#he $iry e%uation)

    syms y(x)dsolve(dif(y, 2) == x