why am I getting this difference in the plotting?
이전 댓글 표시
I have a system of equations:
This system satisfies a relation
For
I plotted the relation
in two ways:
First way by solving the system numerically using ode45 with RelTol 1e-12 and AbsTol 1e-15 and by having the solution for x I plotted y.
Second way by solving the equation
again with ode45 with Reltol 1e-9 and Abstol 1e-12 and then defining y=... and plotting it.
However, the plots are very different and I don't understand the reason why:
Here is the plot by first method:

Here is the plot by second method:

Help is appreciated!
Codes:
%--------------------------------- second method
function[Y] = S_with_I_defined(a,b,x0)
% a function to define for ode45
d=abs(a*x0-b);
function dS = SIpS1_pR(t,y)
dS = -(a*y-b)*(1-y-((1-b)/a)*log(d/abs(a*y-b)));
end
% solving the system and sketching the curves S,I,R
options = odeset('Refine',6,'RelTol',1e-9,'AbsTol',1e-12);
[t,y] = ode45(@SIpS1_pR, [0 1500], x0, options);
Y=y;
end
%-------------------------------------------- first method
function[X,Y] = RK_SI_pS_1_minus_pR7(a,b,x0,y0)
% a function to define for ode45
function dy = SIpS1_pR(t,y)
dy = zeros(2,1);
dy(1) = - a*y(1)*y(2)+b*y(2);
dy(2) = a*y(1)*y(2) -y(2);
end
% solving the system and sketching the curves
options = odeset('Refine',1,'RelTol',1e-12,'AbsTol',1e-18);
[t,y] = ode45(@SIpS1_pR, [0 1500], [x0 y0], options);
X=y(:,1);
Y=y(:,2);
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





