How to solve multivariable ODE

55 visualizaciones (últimos 30 días)
Jessica Dominic
Jessica Dominic el 21 de Oct. de 2020
Respondida: Alan Stevens el 27 de Oct. de 2020
I have the equations:
dx/dt = 2 - 0.09x + 0.038y
dy/dt = 0.066x - 0.038y
x(0) = 0
y(0) = 0
Ultimately I need to solve the ODE and plot for x and y versus time (t). I just don't know how to code for the equations in Matlab.
Thanks

Respuestas (2)

Manvi Goel
Manvi Goel el 27 de Oct. de 2020
In order to solve for a system of differential equations, you could use the dsolve function. You can refer to this link which explains the implementation with an example:

Alan Stevens
Alan Stevens el 27 de Oct. de 2020
If you don't have the symbolic toolbox available you could just do something like the following
% Define gradient function where X(1) = x and X(2) = y
dXdt = @(t,X) [2 - 0.09*X(1) + 0.038*X(2); 0.066*X(1) - 0.038*X(2)];
% Set your timespan
tspan = [0 1]; % Modify as desired
% Set your initial conditions IC = [x(t=0) y(t=0)]
IC = [0 0];
% Call ode solver
[t, X] = ode45(dXdt, tspan, IC);
% Extract x and y
x = X(:,1);
y = X(:,2);
% Plot results
plot(t,x,t,y),grid
legend('x','y')

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by