MATLAB: How to draw a trajectory

chaosodetrajectory

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

Best Answer

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.