How to solve multivariable ODE
43 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (2)
Manvi Goel
am 27 Okt. 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:
0 Kommentare
Alan Stevens
am 27 Okt. 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')
0 Kommentare
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!