Hye,
I have a problem to plot the trajectories of this three variables dynamical system. I know we can use quiver3 but I am not pretty sure how to do it. Can anyone help me? Here is the matlab code
function myode
[t,xa] = ode45(@f,[0 500],[1 0 -1]);
plot3(xa(:,1),xa(:,2),xa(:,3))
grid on
end
function ydot = f(t,x)
if t < -1
z = x(1);
elseif t <= 0
z = x(1) + 1;
else
z = x(1) + 2;
end
ydot = [x(1)+x(2)+z; x(1)+x(2)+x(3); x(3)];
end

댓글 수: 2

Jan
Jan 2017년 2월 7일
편집: Jan 2017년 2월 7일
Are you sure, that you want to integrate from t=0 to t=500? Then checking for t<-1 inside f() is not meaningful.
Peter DH
Peter DH 2017년 2월 7일
sorry, this is not the real functions that I want to solve. I change to simple one for simplicity. The main problem is plotting the directional field of three variables system. Please help me if you have some ideas. Much appreciated. Thanks

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

답변 (1개)

Jan
Jan 2017년 2월 7일

0 개 추천

To get the velocities as input for quiver3, the function to be integrated must be modified:
function myode
[t, xa] = ode45(@f, [0 500], [1, 0, -1]);
dxa = f(t, xa.').';
figure;
quiver3(xa(:,1),xa(:,2),xa(:,3), dxa(:,1),dxa(:,2),dxa(:,3));
grid on
end
function ydot = f(t, x)
if t < -1
z = x(1, :);
elseif t <= 0
z = x(1, :) + 1;
else
z = x(1, :) + 2;
end
ydot = [x(1, :) + x(2, :) + z; x(1, :) + x(2, :) + x(3, :); x(3, :)];
end
Matlab's integrators cannot handle discontinuities. You will get a final position, but from the viewpoint of a scientific application of numerical methods, this is not a trustworthy result. See http://www.mathworks.com/matlabcentral/answers/59582#answer_72047 . As long as you integrate from 0 to 500, the problem concerns the first point t<=0 only, but it is not clean.
Your trajectory explodes at t==270.0578 and you get NaNs.

카테고리

태그

질문:

2017년 2월 7일

댓글:

2017년 2월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by