Changing parameters in an ODE

5 Ansichten (letzte 30 Tage)
Ojaswita
Ojaswita am 30 Aug. 2015
Kommentiert: Star Strider am 10 Sep. 2015
I wish to change one of the parameters at each time step for an ODE solution plot. My function is as follows:
function [t,v]=shig(b,p,m,yo)
[t v] = ode45(@fnsirtry,[0 12],yo);
function fnsir = fnsirtry(t,v)
a = 0.25;
r = 0.14;
fnsir(1) = p - m*v(1)-b*v(1)*v(2)+a*v(3);
fnsir(2) = (b*v(1))- (m + r)*v(2);
fnsir(3) = (r*v(2))-((m+a)*v(3));
fnsir = fnsir(:);
end
end
When I plot the ODE, I want to change the value of b at each step. I have used a code like teh following:
temp = [5 9 12 17 19 24 28 27 22 17 10 7];
beta = 0.0000025*temp;
i = [1 2 3 4 5 6 7 8 9 10 11 12];
for i = 1;
b = beta(:,1)
end
for i = 2;
b = beta(:,2)
end
for i = 3;
b = beta(:,3)
end
for i = 4;
b = beta(:,4)
end
for i = 5;
b = beta(:,5)
end
for i = 6;
b = beta(:,6)
end
for i = 7;
b = beta(:,7)
end
for i = 8;
b = beta(:,8)
end
for i = 9;
b = beta(:,9)
end
for i = 10;
b = beta(:,10)
end
for i = 11;
b = beta(:,11)
end
for i = 12;
b = beta(:,12)
end
P = 5000;
m = 0.013;
yo = [200000 160 0];
[t v] = shig(b,p,m,yo);
w = [159
148
143
137
102
91
85
137
119
108
104
100];
subplot (1,2,1)
plot(t,v(:,2))
%,'-r*','Linewidth',1.5,'MarkerSize',5)
title('Infected Population')
%legend('Disease free state','Test state')
subplot(1,2,2)
plot(w)
Could I please get some light on this,, pls...

Akzeptierte Antwort

Star Strider
Star Strider am 30 Aug. 2015
I don’t understand all the for loops. Assuming your ODE works and integrates as you want it to (I didn’t run your code), I would just do:
for k1 = 1:12
[t{k1}, v{k1}] = shig(beta(:,k1),p,m,yo);
end
and then plot the individual cell vectors. Note that if you define your evaluation times as a vector of discrete times for all integrations, rather than as a two-element range, you can use a matrix to store them rather than a cell array. Your call.
  20 Kommentare
Ojaswita
Ojaswita am 10 Sep. 2015
Yes, I get it. Thanks so much for the help! I'll do it and come back if I face troubles. Thanks a ton for all the time help! I highly appreciate it. Students like me look forward to such sites for help so that we may learn more and apply better. Thank you!
Star Strider
Star Strider am 10 Sep. 2015
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by