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

  • Thread starter Ashkan
  • Start date
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
 

Want to reply to this thread?

"How to access function's (and variable's) value in ODE45 right after each step?" You must log in or register to reply here.

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

Replies
0
Views
3K
  • Posted
Replies
0
Views
2K
Replies
0
Views
1K
Replies
0
Views
4K
  • Posted
Replies
0
Views
2K

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving
Top