필터 지우기
필터 지우기

Error using dsolve in system of first order differential equation

조회 수: 1 (최근 30일)
Arjun Vasan
Arjun Vasan 2021년 4월 11일
답변: Vaibhav 2024년 5월 29일
Hi I am trying to solve a system of ODEs using matlab but am getting errorrs. Here is my code.
a and b are constants
syms S(t) I(t) R(t) a b
eqns = [diff(S,t)== -a*S*I, diff(I,t)==a*S*I-b*I,diff(R,t)==b*I];
ans = dsolve(eqns)
Warning: Unable to find explicit solution.
> In dsolve (line 201)
then I tried this
ans = dsolve(eqns,'Implicit',true)
and got the following
Error using char
Conversion to char from logical is not possible.
Error in dsolve>mupadDsolve (line 286)
if isvarname(char(args{end}))
Error in dsolve (line 194)
sol = mupadDsolve(args, options);

답변 (1개)

Vaibhav
Vaibhav 2024년 5월 29일
Hi Arjun
It seems you are facing issues with solving a system of ordinary differential equations (ODEs).
Due to the nature of your system, an explicit solution might not be available. In such cases, numerical methods are typically used. Functions like ode45, ode23, and ode113 are suitable for obtaining numerical solutions.
Here is how we can approach it:
% Define constants
a = 0.1; % Example value
b = 0.05; % Example value
% Initial conditions [S0, I0, R0]
y0 = [0.99, 0.01, 0]; % Example initial conditions
% Time span
tspan = [0 100]; % From time 0 to 100
% Solve the system
[t, y] = ode45(@(t, y) SIRModel(t, y, a, b), tspan, y0);
% Plot the results
plot(t, y)
legend('S', 'I', 'R')
xlabel('Time')
ylabel('Population')
title('SIR Model Solution')
function dydt = SIRModel(t, y, a, b)
S = y(1);
I = y(2);
R = y(3);
dydt = [-a*S*I; a*S*I - b*I; b*I];
end
Hope it helps!

카테고리

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