Matlab code for Perturbation Analysis
15 ビュー (過去 30 日間)
古いコメントを表示
% Parameters for the SIR model beta = 0.3; % Infection rate gamma = 0.1; % Recovery rate mu = 0.05; % Natural birth rate nu = 0.02; % Natural death rate % System of equations syms S(t) I(t) R(t) eps eq1 = diff(S,t) == mu - beta*S*I - mu*S + eps*(mu - beta*S*I - mu*S); eq2 = diff(I,t) == beta*S*I - gamma*I - nu*I + eps*(beta*S*I - gamma*I - nu*I); eq3 = diff(R,t) == gamma*I - mu*R + eps*(gamma*I - mu*R); % Initial conditions S0 = 0.9; I0 = 0.1; R0 = 0;
conditions = [S(0)==S0, I(0)==I0, R(0)==R0];
% Solve the system of equations [SSol, ISol, RSol] = dsolve([eq1, eq2, eq3, conditions]);
% Perturbation terms S_perturb = SSol + eps*dsolve(diff(S,t) == mu - beta*SSol*ISol - mu*SSol); I_perturb = ISol + eps*dsolve(diff(I,t) == beta*SSol*ISol - gamma*ISol - nu*ISol); R_perturb = RSol + eps*dsolve(diff(R,t) == gamma*ISol - mu*RSol);
% Plot the solutions tspan = 0:0.1:100; s = subs(S_perturb, eps, 0.1); i = subs(I_perturb, eps, 0.1); r = subs(R_perturb, eps, 0.1);
figure; plot(tspan, s, 'b', tspan, i, 'r', tspan, r, 'g'); title('Perturbation Analysis of SIR Model'); xlabel('Time'); ylabel('Population'); legend('Susceptible', 'Infected', 'Recovered');
Error in dsolve (line 193) sol = mupadDsolve(args, options);
Error in Perturbation (line 22) S_perturb = SSol + eps*dsolve(diff(S,t) == mu - beta*SSol*ISol - mu*SSol); Please help fix the error.
0 件のコメント
回答 (1 件)
Arnav
2024 年 9 月 23 日
Hi,
I understand that you are facing an error while solving the symbolic differential equations using dsolve. This is due to dsolve not being able to find a symbolic solution to the equations.
This can be solved by using a numeric solver like ode45 as:
% Parameters for the SIR model
beta = 0.3; gamma = 0.1; mu = 0.05; nu = 0.02; eps = 0.1;
% Define the system of differential equations
sir_ode = @(t, y, eps) [
mu - beta * y(1) * y(2) - mu * y(1) + eps * (mu - beta * y(1) * y(2) - mu * y(1));
beta * y(1) * y(2) - gamma * y(2) - nu * y(2) + eps * (beta * y(1) * y(2) - gamma * y(2) - nu * y(2));
gamma * y(2) - mu * y(3) + eps * (gamma * y(2) - mu * y(3))
];
% Initial conditions
y0 = [0.9; 0.1; 0]; tspan = [0 100];
% Solve the system using ode45
[t, y] = ode45(@(t, y) sir_ode(t, y, eps), tspan, y0);
You can refer to the below documentation for more information on dsolve function:
Hope it helps!
1 件のコメント
Sam Chak
2024 年 9 月 23 日
Hi @Arnav
I very understand that you wish to provide technical assistance to the original poster (@Sunday) on the S.I.R. model while partially supplying the code for solving the S.I.R. differential equations using dsolve(). However, your code does not address the perturbation analysis as requested by the OP.
You can refer to the documentation below for more information on perturbation analysis:
- Perturbation Analysis - San José State University
- IEEE Xplore Article: Perturbation analysis explained (behind a paywall)
- SpringerLink Article: Perturbation Analysis (behind a paywall)
Hope it helps!
参考
カテゴリ
Help Center および File Exchange で Equation Solving についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!