How do I save an output to an ODE at t =infinity for various values of a parameter and plot Output Vs Parameter

3 views (last 30 days)
I'm using ODE45 and I'm running a loop on a parameter of an ODE, and I'm trying to plot the output of the parameter against the value of the parameter at t = infinity. My code is
for b = [0.0002:0.0001:0.0006]
fprintf('', b)
g= 0.1
s= 0.3
f = @(t,x) [-b.*x(1)*x(2) + s.*x(3); b.*x(1)*x(2)-g.*x(2); g.*x(2)-s.*x(3)]
[t,xa]=ode45(f,[0 100], [650 50 0]);
plot(t,xa(:,2))
end

Accepted Answer

Ameer Hamza
Ameer Hamza on 29 Sep 2020
Edited: Ameer Hamza on 29 Sep 2020
The best way would have been to find an analytical solution of ODE and then use the limit() to find value at t=infinity. But for your ODEs, such a solution does not exist. So you will need to rely on numerical methods. You can solve the equation for a long tspan such that the output converges at the end of tspan. The value at t=infinity can be approximated by the convergence value
B = 0.0002:0.0001:0.0006;
g = 0.1;
s = 0.3;
t_inf_values = zeros(size(B));
for i = 1:numel(B)
b = B(i);
fprintf('b = %f\n', b)
f = @(t,x) [-b.*x(1)*x(2) + s.*x(3); b.*x(1)*x(2)-g.*x(2); g.*x(2)-s.*x(3)];
[t,xa] = ode45(f, [0 1000], [650 50 0]);
t_inf_values(i) = xa(end,2);
end
plot(B, t_inf_values);

More Answers (1)

Bernard Sayegh
Bernard Sayegh on 29 Sep 2020
Thanks for the advice, that should help. Thanks Ameer

Categories

Find more on Programming in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!