Solving ODE with two variables and derivatives

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)

Antworten (1)

Guru Mohanty
Guru Mohanty am 11 Mai 2020

0 Stimmen

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 Kommentar

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.

Melden Sie sich an, um zu kommentieren.

Tags

Gefragt:

am 8 Mai 2020

Kommentiert:

am 8 Nov. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by