1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Coupled First Order Equations

  1. Jul 30, 2010 #1
    1. The problem statement, all variables and given/known data
    I have a large project involving Runge Kutta numerical solutions of differential equations. I understand the Runge Kutta method and I've done it before, but my problem involves taking the differential equation

    y''=sin(3y(t)), t>=0

    and reexpressing this IVP into coupled first order equations. I have seen examples where people have done something similiar like set

    z'=sin(3y(t))
    y'=z

    and there is a guy in my class that swears that this is right, but frankly that doesn't make sense to me in this case. If someone could help me understand how to do this correctly, I feel like I have a decent understanding of the numerical solution method. I have been asked to use the first order Runge Kutta method, but I have never used this method with coupled equations that looks anything like this...


    2. Relevant equations
    y''=sin(3y(t)), t>=0


    3. The attempt at a solution
    Matlab Code:
    clc;
    clear all;
    close all;
    format long g;

    N=input('current value of N')
    deltat=20./N;
    y=1;
    z=0;
    h = deltat;
    t = 0:h:20;
    i=0;

    for i = 1:length(t)
    T(i) = i*h;
    Y(i) = y;
    k1 = (z);
    l1 = sin(3.*(y));
    k2 = ((z)+(h./2).*l1);
    l2 = sin(3.*((y)+(h./2).*k1));
    k3 = ((z)+(h./2).*l2);
    l3 = sin(3.*((y)+(h./2).*k2));
    k4 = ((z)+h.*l3);
    l4 = sin(3.*(y+h.*k3));
    z = z + (h./6).*(l1+2.*l2+2.*l3+l4);
    y = y + (h./6).*(k1+2.*k2+2.*k3+k4);
    end

    Y = Y'

    plot(T,Y);
    1. The problem statement, all variables and given/known data



    2. Relevant equations



    3. The attempt at a solution
     
  2. jcsd
  3. Jul 30, 2010 #2
    Mathematical way to do it is:

    change the parameters so:
    u=y
    v=y'

    u'=v : first 1st order equation.

    v'=sin(3*u) : second 1st order equation.


    now you have a system of two 1st order differentials equations.
    it's done basically by a change of variables :)
     
  4. Jul 30, 2010 #3
    Can someone tell me how to solve this differential equation in matlab so that I can check my numerical solution? (I'm not asking for an answer, just a way to check my answer)
     
  5. Jul 30, 2010 #4
    Look up the help docs for ODE45/23/etc for a way to solve this in matlab. You will find all the examples convert the second order diff eq to two first order or even three. You already have what you need to pretty much copy and paste matlab example code and run your problem. This in control theory is described as the 'state space representation'.

    What that friend of yours is doing is converting the second order diff eq, to two first order diff eqs (as gomunk51 already mentioned). Then it's easy to convert things to the RK4 form. You also have a couple of other varieties of RK which do the job based on your requirement for accuracy, precision and time-to-run. See Kreyszig-Engg math. You also have the modified RungeKutta-Nystrom method described there, which generalizes the standard RK method to apply to a second order ODEs

    A bit of matlab advice: 1. Don't post code online, no one wants to shift through your code (neither do your instructors) 2. Don't use vector operations (the hadamard dot) on scalars. 3. By declaring your Y(i) before you calculate the i^th y, you are losing your last calculation. (Not a problem for your case) 4. Such coupled differential equations are best solved as arrays, (don't worry about this right now) 5. Indent your code (select all, then press ctrl+I in matlab editor)

    What you have done looks all right, but I don't remember rk4 in detail.
     
  6. Jul 31, 2010 #5
    If these equations are correct then I must not understand how to do the stage constants for the iteration.

    If
    [tex]\frac{dz}{dt} = sin(3y(t)) [/tex]

    [tex]\frac{dy}{dt} = z [/tex]

    then

    [tex]\frac{dz}{dt} = f[t, y(t)] [/tex]

    [tex]\frac{dy}{dt} = f[t, z(t)] [/tex]

    (I think)

    How are they "coupled" in that I don't see that they have a dependency on each other. I understand the runge kutta method when they have a dependency on each other, but how does solving for z or y help you solve for the other?... I don't see how the stage constants rely on each other.

    I would understand if it was

    [tex]\frac{dy}{dt} = f[t, y(t), z(t)] [/tex]

    [tex]\frac{dz}{dt} = F[t, y(t), z(t)] [/tex]

    If you could help me understand this, I'd appreciate it. It would make since if y and z were in both first order equations.
     
  7. Jul 31, 2010 #6
    Well.... anyway my attempt at this was:

    [tex]k1 = z_{i}[/tex]

    [tex]l1 = sin(3.*(y_{i}));[/tex]

    [tex]k2 = z_{i}+\frac{h}{2}*l1[/tex]

    [tex]l2 = sin(3*(y_{i}+\frac{h}{2}*k1))[/tex]

    [tex]k3 = z_{i}+\frac{h}{2}*l2[/tex]

    [tex]l3 = sin(3*(y_{i}+\frac{h}{2}*k2))[/tex]

    [tex]k4 = z_{i}+h*l2[/tex]

    [tex]l4 = sin(3*(y_{i}+h*k2))[/tex]

    [tex]z_{i+1} = z_{i} + \frac{h}{6}*(l1+2*l2+2*l3+l4)[/tex]

    [tex]y_{i+1} = y_{i} + \frac{h}{6}*(k1+2*k2+2*k3+k4)[/tex]

    I doubt this is correct... In the event that it is, could someone explain it to me better. Either way, I would like to understand this.
     
  8. Aug 1, 2010 #7

    HallsofIvy

    User Avatar
    Staff Emeritus
    Science Advisor

    No, this is incorrect.

    This is correct.


     
  9. Aug 1, 2010 #8
    Okay. I might be on to something with this:

    [tex]u = y [/tex]

    [tex]v = y' [/tex]

    [tex]v' = sin(3u) [/tex]

    [tex]u' = \frac{-1}{3v} cos(3u) [/tex]

    This way it's in the form:

    [tex]\frac{dv}{dt} = f [/tex]

    [tex]\frac{du}{dt} = F[v, u] [/tex]

    So.... during runge kutta iterations, I'd have to solve for v to solve for u for each iteration.

    Is this on the right track? It makes more sense to me anyway... assuming I did the itegration right. I'm not sure if or how I'd do anything with time t though in the stage constants.
     
  10. Aug 1, 2010 #9
    Actually, I'm sure that

    [tex]u' = \frac{-1}{3v} cos(3u) [/tex]

    is not correct. When I differentiate it, it does not work out to be the original equation. What method of integration would be used to solve it? I'm sure it's integrated over time and v and u are functions of time.
     
  11. Aug 1, 2010 #10
    When you said that the two first order functions were incorrect... I am confused because you said that was correct earlier. I am confused and not sure what to do. I don't see how one could use the runge kutta method with those functions.

    I am under the impression that in many cases when you use runge kutta, you integration a high order function and form two functions of 2 or 3 variables.

    It feels like if I took the function and integrated it and used both of these to solve each equation simultaneously, I could come out with an answer for y. What I tried to do sort of makes sense, but I don't think the integral is right. Any guidance is much appreciated.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Coupled First Order Equations
Loading...