Phase portrait doesn't work

Hello to everyone. I have a little problem with my task. I don't know if it is right. I am not sure if all the points are okay and the figure which draws it's right. If someone coul help me I will be very happy. I am really no sure if i make it the way i should and if the graphic is supposed to look like this.
It is given the system
x’ = y^3 − 5y − x
y’ = −x – y
The tasks are to find:
a) Find equivalent points on the system.
b) Draw a phase portrait of the system.
c) Determine which equivalent points are stable.
d) To solve the Cauchy problem for a system with initial data x (0) = 0, y (0) = 5 made animation when moving to the point (x (t), y (t)) in the phase space when the time t varies from 0 to 3
%a function which file name is sys.m
function res = sys(t,x)
res = [x(2)^3-5*x(2)-x(1); -x(1)-x(2)];
%a phase portrait
plot([-10,10],[0,0]);
hold on;
plot([0,0],[-10,10]);
hold on;
syms t y1 y2;
f = @(t, y) [y1.^3 - 5.*y1 - y2; -y2 - y1];
F = f(t,[y1;y2]);
[x,y] = solve(F(1), F(2), y1, y2);
plot(x, y, '*');
axis([-10, 10, -10, 10]);
[x0, y0] = ginput(1);
while 1
[t, x] = ode45(@sys, [0, 10], [x0, y0]);
plot(x(:,1), x(:,2), 'g')
[t, x] = ode45(@sys, [0, -10], [x0, y0]);
plot(x(:,1), x(:,2), 'b')
[x0, y0] = ginput(1);
end
%animation
[t,x] = ode45(@sys, [0, 3], [0, 5]);
for k = 1:length(x)
plot(x(1:k,1),x(1:k,2), 'g');
hold on;
plot(x(k,1),x(k,2), 'x');
axis([-10,10,-10,10]);
M = getframe;
hold off;
end
movie(M);

4 个评论

This line shouldn't work. Didn't you have any problems?
It is working but I don't know if it is correct because a friend give me the task and I don't understand much. So i wanted to ask if someone know if it is okay. It is the same graphic that i uploaded. Do you think there is a better way ?
I think it's ok

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Graphics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by