Solving ODE with two variables and derivatives
27 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi guys i need help solving this system. I symplified the system to its basics. I want to get and plot y(t) in the end. My system tells me it doesnt know r. How can i tell the system to solve the ode of r within the ode of y? Where do I put the r0 in? I am an beginner in Matlab though :D Thank you very very much!! Stay safe and healthy you all!
initial conditions: y0 and r0
parameters: B,C,D
A is a function of y
......
tspan=linspace(0,10); %for both integrals y and r
[t1,y1] = ode45(@(t,y) Simulation(t,B,C,D,E,F), tspan, y0);
.....
function dydt = Simulation (t,B,C,D,E,F)
drdt = -C*(B+D);
A= E-y*F;
dydt = A- ( (y/r) * drdt);
end
...
plot(t1,y1)
0 commentaires
Réponses (1)
Guru Mohanty
le 11 Mai 2020
Hi, I understand you are trying to solve the system of two variable ODE. Numerically, you can do this using ode45. Here is the modified code for it.
clc;clear all;
% Initial Conditions
y0=0;
r0=0;
% Constant Declaration
B=1; C=1; D=2; E=1; F=1;
con1=-C*(B+D);
tspan=linspace(0,10); %for both integrals y and r
[t1,z1] = ode45(@(t,z)Simulation(t,z,E,F,con1), tspan, [r0;y0]);
plot(t1,z1);
function dOutdt = Simulation (t,z,E,F,con1)
dOutdt=zeros(2,1);
y=z(1);
r=z(2);
dOutdt(1) = con1;
A= E-y*F;
dOutdt(2) = A - ( (y/r) * dOutdt(1));
end
1 commentaire
Suhaib Salah
le 8 Nov 2021
Dear Guru,
I copied and pasted this code into matlab. It told me that the word simulation is not valid.
How to solve this?
Regards.
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!