Solving ODE with two variables and derivatives
27 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Guru Mohanty
2020 年 5 月 11 日
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 件のコメント
Suhaib Salah
2021 年 11 月 8 日
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.
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!