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

  • Thread starter Ashkan
  • Start date
  • #1
4
0
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
 

Answers and Replies

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

Replies
5
Views
8K
Replies
3
Views
2K
  • Last Post
Replies
4
Views
2K
Replies
0
Views
3K
Replies
2
Views
813
Replies
2
Views
2K
Replies
1
Views
2K
Replies
6
Views
33K
Top