Matlab code for Perturbation Analysis

조회 수: 15 (최근 30일)
Sunday
Sunday 2024년 9월 19일
댓글: Sam Chak 2024년 9월 23일
% 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.

답변 (1개)

Arnav
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
Sam Chak 2024년 9월 23일
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:
Hope it helps!

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

카테고리

Help CenterFile Exchange에서 Equation Solving에 대해 자세히 알아보기

태그

제품


릴리스

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by