How to solve multivariable ODE

43 ビュー (過去 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 Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by