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)

回答(1 个)

Guru Mohanty
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
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 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