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

How to access function's (and variable's) value in ODE45 right after each step?

  1. Jul 2, 2010 #1
    first I was thinking it was very easy to obtain a variable's or function's value after each step within ode45 subfunction. But just yesterday I found out all I had done before might be incorrect! just see the MATLAB code below:

    I believed the two plots should be exactly the same but they are not! I am very disappointed and confused! can someone explain why they are not the same? and if t2 and F2 are not the actual values after each step, how can I obtain actual values of variable (t) and function (F) after each step?

    many thanks in advance,
    Ashkan


    function tdelay
    clear
    clc
    global Fd ts i F2 t2
    Fd=8;
    F0=5;
    ts=0.01;
    i=1;

    % F=(F0-Fd)*exp(-t./ts)+Fd;

    [t,F]=ode45(@werely,[0 1],F0);

    plot(t,F)
    hold on
    plot(t2,F2,'r')
    end

    function dF=werely(t,F)
    global ts Fd i t2 F2
    t2(i)=t;
    F2(i)=F;
    dF=(1/ts)*(-F+Fd);
    i=i+1;
    end
     
  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: How to access function's (and variable's) value in ODE45 right after each step?
Loading...