How to solve Two coupled ODE problem

조회 수: 1 (최근 30일)
Azam Axel
Azam Axel 2016년 9월 6일
댓글: Azam Axel 2016년 11월 6일
hello all,
actually, i have some problem about to solve two coupled ODE that are dependent on each other. if u all have time can u give me some guide about to coding with two coupled equations problem below and plot the graph :-
function dydt = odefun1(t,y,Aq,Bq,Cq,Ay,By,Cy)
A=1;
B=2;
C=1;
D=3;
E=1;
F=1;
h=1;
Aq=y(1);
Bq=y(2);
Ay=y(3);
By=y(4);
dydt = zeros(4,1);
dydt(1) = F*dydt(2)-D*Bq-E*Aq;
dydt(2) = (C*Aq-B*By-h*Ay)/A;
dydt = [dydt(1) ; dydt(2) ];
t_start = 0;
t_end = 10; %final time in seconds.
%time_span =[ t_start t_end];
time_span =t_start:0.09:t_end;
initial_position = 0;
initial_speed = 0;
x0 = [initial_position initial_speed];
[t,y]=ode45(@odefun1,time_span,x0);
plot(t,y(:,1));
hold on;
plot(t,y(:,2));
end
hope u all can answer this question.. thank you in advance. best regards, azam
  댓글 수: 2
James Tursa
James Tursa 2016년 9월 22일
편집: James Tursa 2016년 9월 22일
If y is a 4-element vector, why are you building a dydt vector that has only 2 elements? If dydt(1) depends on dydt(2), why aren't you calculating dydt(2) before you calculate dydt(1)?
Azam Axel
Azam Axel 2016년 9월 26일
Thank you James for your answer,but i'm still having the same problem though. i changed my code as shown below. no error but cannot produce the graph instead. can u guide me with example code. very appreciate if u can answer this.. tq
function dydt = odefun1(t,y,Aq,Bq,Cq,Ay,By,Cy)
A=1;
B=2;
C=1;
D=3;
E=1;
F=1;
h=1;
Aq=y(1);
Bq=y(2);
Ay=y(3);
By=y(4);
dydt = zeros(4,1);
dydt(1) = (C*Aq-B*By-h*Ay)/A;
dydt(2) = F*dydt(1)-D*Bq-E*Aq;
t_start = 0;
t_end = 10; %final time in seconds.
%time_span =[ t_start t_end];
time_span =t_start:0.09:t_end;
initial_position = 0;
initial_speed = 0;
x0 = [initial_position initial_speed];
[t,y]=ode45(@odefun1,time_span,x0);
plot(t,y(:,1));
hold on;
end

댓글을 달려면 로그인하십시오.

답변 (1개)

PUJARI MURAGA
PUJARI MURAGA 2016년 11월 4일
I have solution for you.
Did you got ?
  댓글 수: 1
Azam Axel
Azam Axel 2016년 11월 6일
can you share with me what you got.. tq in advance pujari 4 answer this question..

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by