How to store conditional values during iteration by using Ode45?
Afficher commentaires plus anciens
I want to store data of each iteration, including the conditional values. Is there a way to do this? Thanks!
There is an example where 'b' is the conditional value. And the goal ([b0,t,X1]) is as follows:
1 0 1.0000
1 1.0000 1.5378
1 2.0000 1.6115
1 3.0000 1.6175
1 4.0000 1.6180
1 5.0000 1.6180
2 0 1.0000
2 1.0000 1.9317
2 2.0000 1.9987
2 3.0000 2.0000
2 4.0000 2.0000
2 5.0000 2.0000
3 0 1.0000
3 1.0000 2.2584
3 2.0000 2.3036
3 3.0000 2.3028
3 4.0000 2.3028
3 5.0000 2.3028
Code:
save=[]
t0=0;
tf=15;
a0=1
global b0;
for b0=1:1:3
X=[a0]
[t, X1] = ode45(@fun,[t0:0.1:tf], X);
% X2=[b0,t,X1(1)];
X2=[t,X1];
save=[save;X2]
end
function fx=fun(t,x)
fx=zeros(1,1);
global b0
b=b0
fx(1)=x(1)-x(1)^2+b
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Ordinary Differential Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!