how to draw a trajectory

조회 수: 33 (최근 30일)
mostafa
mostafa 2014년 4월 22일
댓글: mostafa 2014년 4월 22일
Hi
i have a differential equation like this:
x'' + x + x^2 = 0
its a chaos problem and i want to display the trajectories.it has two fix point, a saddle at (-1,0) and a repellor at (0,0).
we can transform the equation to ODE by this:
x'= y
y'= -x -x^2
  댓글 수: 1
mostafa
mostafa 2014년 4월 22일
if true
x0 = input('Enter the initial position [x y] - ');
tspan=[0,10*pi];
[t,x]=ode45(@simple,tspan,x0,[]);
plot(x(:,1),x(:,2));
title('Lorenz Model Trajectory XZ')
xlabel('X')
ylabel('Z')
end
but it give me error. i write equations in simple.m .

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

채택된 답변

Mischa Kim
Mischa Kim 2014년 4월 22일
Mostafa, try something like
function my_phase()
IC = rand(10,2);
hold on
for ii = 1:length(IC(:,1))
[~,X] = ode45(@EOM,[0 2],IC(ii,:));
x = X(:,1);
y = X(:,2);
plot(x,y,'r')
end
xlabel('x')
ylabel('y')
grid
end
function dZ = EOM(t, z)
dZ = zeros(2,1);
x = z(1);
y = z(2);
dZ = [ y;...
- x - x^2];
end
You can use the IC vector to place the initial conditions to specifically show the dynamics around the fixed points.
  댓글 수: 3
Mischa Kim
Mischa Kim 2014년 4월 22일
As I pointed, use the IC vector, e.g.,
IC = bsxfun(@plus, [-1 0], rand(100,2)-0.5*ones(100,2));
You probably need to zoom to display the interesting part of the plot.
mostafa
mostafa 2014년 4월 22일
thanks a lot. i got it

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

추가 답변 (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