Solving ODE with two variables and derivatives
조회 수: 37 (최근 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!