How to solve multivariable ODE

59 次查看(过去 30 天)
Jessica Dominic
Jessica Dominic 2020-10-21
回答: Alan Stevens 2020-10-27
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

回答(2 个)

Manvi Goel
Manvi Goel 2020-10-27
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 2020-10-27
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')

类别

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