Borrar filtros
Borrar filtros

Error using dsolve in system of first order differential equation

1 visualización (últimos 30 días)
Arjun Vasan
Arjun Vasan el 11 de Abr. de 2021
Respondida: Vaibhav el 29 de Mayo de 2024
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);

Respuestas (1)

Vaibhav
Vaibhav el 29 de Mayo de 2024
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!

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by