Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MATLAB Time dependent ODE

  1. Aug 26, 2010 #1
    Have been struggling with errors galore on this one. I am not too conversant with ODEs in MATLAB. The problem is as follows. I have to solve these two ODEs for A1 and A2.

    A1dot = k2*A2 - k1*A1 - k3*A1/(k4 + A1) + R
    A2dot = k1*A1 - k2*A2

    Here R is a function of time defined as follows:

    R = 5, when 7<t<7.2
    R=0 otherwise

    R is periodic and this pattern repeats. Like R takes the value 5 when 7<t<7.2, when 14<t<14.2, 21<t<21.2 and so on, and is zero everywhere else.

    My code for obtaining the vector of differentials is as follows. It takes in t, A, T and R. The T is a time vector for the R parameter. I use the interp1 command as outlines in a sample MATLAB time dependent ODE code.

    function dA = trial(t,A,T,R)
    Rin = interp1(T,I,t);

    V1 = 40; V2 = 100; k1 = 0.2; k2 = 0.2;k3 = 2; k4 = 0.003;

    dA(1) = k2*A(2) - k1*A(1) - (k3*A(1))/(k4 + A(1)) + Rin;
    dA(2) = k1*A(1) - k2*A(2);
    dA = dA(:);

    end

    I then call this at the command line. I define R suitably using a for loop (using rem and other stuff) and define T to be the same as t0:1:tf as in the ODE tspan.

    Then I solve for A.

    [t,A]=ode15s(@trial, [to,tf],Anot,[],T,R);

    I seem to be getting strange plots. I am concerned if the above method as such works, or the problem is with my parameter values (of which am not too sure as yet). So if the above code and the way of doing it is right, I can go about changing parameters and seeing.

    Any help is highly appreciated.

    Thanks..
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted



Similar Discussions: MATLAB Time dependent ODE
  1. ODE in Matlab (Replies: 3)

  2. ODE matlab (Replies: 2)

Loading...