Results 1 to 7 of 7
Like Tree1Thanks
  • 1 Post By Krisly

Thread: solving 2nd order differential equation system in matlab

  1. #1
    Newbie
    Joined
    Oct 2015
    From
    iran
    Posts
    4

    Question solving 2nd order differential equation system in matlab

    Hi
    I have to solve a 2nd order differential equation system(9*9) in matlab and I have some problems with it:
    eq1=f(x1,x2,.....,x9,x1'',x2'',....,x9'')=0
    .
    .
    eq9

    they are linear equations.
    The initial conditions: x1(0)=x2(0)=....x9(0)=0, x1'(0)=.....x9'(0)=0
    One of the problem is when I want to solve them by ode45 ,it needs to introduce x1'', x2'' ,.... in each equation.
    what should I do? please help me.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Junior Member
    Joined
    Apr 2015
    From
    Denmark
    Posts
    43
    Thanks
    2

    Re: solving 2nd order differential equation system in matlab

    Well ode45 only solves 1st order differential equations, so first off you have to rewrite every n'th order differential equation to a connected system of n first order differential equations. And then solve all these as your final system.
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Oct 2015
    From
    iran
    Posts
    4

    Re: solving 2nd order differential equation system in matlab

    Thank you for your answer, I did that.
    this is the basic program:
    [T OUTPUT]=ode45(@odefunc,t,IC)

    And I have to write an ode function like this:

    function output=odefun (s,t)

    x1=s(1)
    y1=s(2) %y1=x1'
    x2=s(3)
    y2=s(4) %y2=x2'
    .
    .
    .
    x9=s(17)
    y9=s(18) %y9=x9'


    output=[y1;
    f1(x1,x2,.....,x9,x1'',x2'',....,x9'');
    y2;
    f2;
    .
    .
    .];
    Is there any way to replace (x'')s by a variable that could be familiar to matlab? I can't replace them by y1' or diff(y1)!
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Newbie
    Joined
    Oct 2015
    From
    iran
    Posts
    4

    Re: solving 2nd order differential equation system in matlab

    How could I show to matlab that for example x1'' is the first order differential of y1?
    thank you.
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Junior Member
    Joined
    Apr 2015
    From
    Denmark
    Posts
    43
    Thanks
    2

    Re: solving 2nd order differential equation system in matlab

    Well as an example given the following to differential equations:

     \frac{d^{2} x}{d{t}^{2}} = -\frac{C_{d} \cdot A \cdot \rho}{2 \cdot m} \cdot \left( \left( \frac{dx}{dt} \right)^{2}+\left( \frac{dy}{dt}^{2} \right) \right) ^{\frac{1}{2}} \cdot \frac{dx}{dt}
     \frac{d^{2} y}{d{t}^{2}} = -\frac{g}{m}-\frac{C_{d} \cdot A \cdot \rho}{2 \cdot m} \cdot \left( \left( \frac{dx}{dt} \right)^{2}+\left( \frac{dy}{dt}^{2} \right) \right) ^{\frac{1}{2}} \cdot \frac{dy}{dt}

    Can be rewritten where you introduce following:

    z_{1} = x
    z_{2} =y
    z_{3} = \frac{dx}{dt}
    z_{4} = \frac{dy}{dt}

    Then the system of first order differential equation from the above will be:

    \frac{dz_{1}}{dt} = z_{3}
    \frac{dz_{1}}{dt} = z_{4}
    \frac{dz_{1}}{dt} =  -\frac{C_{d} \cdot A \cdot \rho}{2 \cdot m} \cdot \left( \left( x_{3} \right)^{2}+\left( z_{4}^{2} \right) \right) ^{\frac{1}{2}} \cdot z_{3}
    \frac{dz_{1}}{dt} = -\frac{g}{m}-\frac{C_{d} \cdot A \cdot \rho}{2 \cdot m} \cdot \left( \left( z_{3} \right)^{2}+\left( z_{4}^{2} \right) \right) ^{\frac{1}{2}} \cdot z_{4}


    Then the correspondent matlab code for the above will look like this:

    function [dzdt] = odefunB(t, z,Cd,A,p,m,g)

    dzdt = [
    z(3);
    z(4);
    - (Cd*A*p/(2*m)) * sqrt((z(3)^2 + z(4)^2))*z(3);
    -g/m - (Cd*A*p/(2*m)) * sqrt((z(3)^2 + z(4)^2))*z(4)];
    end

    Where each line is one of the right hand sides of the first order differential equations above, and then all the conditions comes like this:

    fineness = 1000;
    startangel = 30;
    initialspeed = 500;
    m = 0.55;
    Cd = 0.5;
    d = 0.07;
    A = (pi*d^2)/4;
    p = 1.2041;
    g = 9.82;
    tspan = linspace(0,30,fineness);
    z0 = [0 2 cos(startangel/180 * pi)*initialspeed sin(startangel /180 * pi)*initialspeed];

    [t,z] = ode45(@(t,z) odefunB(t,z,Cd,A,p,m,g),tspan,z0);

    Hope the example can help you
    Thanks from topsquark
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Junior Member
    Joined
    Apr 2015
    From
    Denmark
    Posts
    43
    Thanks
    2

    Re: solving 2nd order differential equation system in matlab

    ohh i should mention that m,Cd,d,A,p and g are all constants
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Newbie
    Joined
    Oct 2015
    From
    iran
    Posts
    4

    Re: solving 2nd order differential equation system in matlab

    I couldn't explain what exactly is the problem.

    the functions that I have are like these:
    f1=A11*x1''+A12*x2''+A13*x3''+......+A19*x9''+B11* x1+B12*x2+.....+B19*x9
    f2=A21*x1''+A22*x2''+A23*x3''+......+A29*x9''+B21* x1+B22*x2+.....+B29*x9
    .
    .
    .f9=A91*x1''+A92*x2''+A93*x3''+......+A99*x9''+B91 *x1+B92*x2+.....+B99*x9

    %A & B are constant

    so in function as I said:
    output=[s(2);
    -(A12*x2''+A13*x3''+......+A19*x9''+B11*s(1)+B12*s( 3)+.....+B19*s(17))/A11; % the problem is exactly these (x2'' , x3'' ..... x9'') in every EQ
    s(4);
    -(A21*x1''+A23*x3''+......+A29*x9''+B21*s(1)+B22*s( 3)+.....+B29*s(17))/A22;
    .
    .
    .];

    according to ur exanple , in those equations there is only ONE 2nd order differential in each equation. so the solution and program is simple. But in this problem it's kind of complicated .
    thank you again for ur time. If you know how should I solve it, please let me know.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 0
    Last Post: Jun 20th 2014, 06:54 AM
  2. Solving a System of First Order Differential Equations
    Posted in the Differential Equations Forum
    Replies: 1
    Last Post: Nov 16th 2010, 10:08 PM
  3. MATLAB Second order nonlinear differential equation
    Posted in the Math Software Forum
    Replies: 2
    Last Post: Dec 15th 2008, 07:00 PM
  4. Replies: 2
    Last Post: Nov 25th 2008, 09:29 PM
  5. Matlab to solve first order differential equation
    Posted in the Math Software Forum
    Replies: 5
    Last Post: Jun 26th 2008, 03:03 AM

Search tags for this page

Click on a term to search for related topics.

Search Tags


/mathhelpforum @mathhelpforum