Changing parameters in an ODE

조회 수: 5 (최근 30일)
Ojaswita
Ojaswita 2015년 8월 30일
댓글: Star Strider 2015년 9월 10일
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...

채택된 답변

Star Strider
Star Strider 2015년 8월 30일
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
Ojaswita
Ojaswita 2015년 9월 10일
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 2015년 9월 10일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by