ODE23 taking in 3 variables

조회 수: 2 (최근 30일)
WhatIsMatlab-
WhatIsMatlab- 2016년 4월 20일
편집: WhatIsMatlab- 2016년 4월 20일
I can run this function with 2 z values but when I try to add another z value I get an error. Do you know how to run this function for 3 z values?
Error: Index exceeds matrix dimensions.
function dxdy = TY3(t,z)
dxdy = [z(3); 1*z(3)+2*z(2)+3*z(1)];
[t,z] = ode23(@TY3,[0 30],[1 0 ]);
plot(t,z(:,1),'k','LineWidth',2);

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 20일
You have 3 variables z(1),z(2) and z3, you need to write 3 equations dydx(1),dydx(2) and dydx(3), for example
dxdy = [z(3); 1*z(3)+2*z(2)+3*z(1);0]
and call ode23 with 1x3 array representing initial conditions
[t,z] = ode23(@TY3,[0 30],[1 0 1 ]);
plot(t,z(:,1),'k','LineWidth',2);
  댓글 수: 3
Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 20일
I just gave an example, you have to provide the third equation and the initial conditions
WhatIsMatlab-
WhatIsMatlab- 2016년 4월 20일
편집: WhatIsMatlab- 2016년 4월 20일
Ok thanks!! I got it working.

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

추가 답변 (0개)

카테고리

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