Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Why it plots more than just one point and how do I get rid of them

조회 수: 1 (최근 30일)
Stefania Maria
Stefania Maria 2019년 12월 10일
마감: MATLAB Answer Bot 2021년 8월 20일
function xp=h2(t,x)
xp=x;
xp(1)=(x(2)) .^2 - 70.*x(2);
xp(2)=(x(1)) .^2 +134.*x(1) - 64 .*x(2);
hold on
[t,x]=ode23('h2', [0,100], [0,0]);
plot(x(:,1), x(:,2), 'kx')
[t,x]=ode23('h2', [0,100], [-64,70]);
plot(x(:,1),x(:,2), 'bx')
[t,x]=ode23('h2', [0,100], [-134,0]);
plot(x(:,1), x(:,2), 'kx')
[t,x]=ode23('h2', [0,100], [55.4/2,70]);
plot(x(:,1), x(:,2), 'kx')
[t,x]=ode23('h2', [0,100], [-323.4/2,70]);
plot(x(:,1), x(:,2), 'kx')
When I plot [-64,70] (stable node) and [55.4/2,70] (saddle), it doesn't appear just one 'x' on the given coord. but it plots a spiral of 'x's starting from those points to [0,0] (focus) point. How do I make the spiral disappear, and have only one 'x' point for each coord?

답변 (1개)

Star Strider
Star Strider 2019년 12월 10일
The code plots more than one point because you told it to.
Revised code:
function xp=h2(t,x)
xp=zeros(2,1);
xp(1)=(x(2)) .^2 - 70.*x(2);
xp(2)=(x(1)) .^2 +134.*x(1) - 64 .*x(2);
end
hold on
[t,x]=ode23(@h2, [0,100], [0,0]);
plot(x(:,1), x(:,2), 'kx')
[t,x]=ode23(@h2, [0,100], [-64,70]);
plot(x(:,1),x(:,2), 'bx')
[t,x]=ode23(@h2, [0,100], [-134,0]);
plot(x(:,1), x(:,2), 'kx')
[t,x]=ode23(@h2, [0,100], [55.4/2,70]);
plot(x(:,1), x(:,2), 'kx')
[t,x]=ode23(@h2, [0,100], [-323.4/2,70]);
plot(x(:,1), x(:,2), 'kx')
hold off
What result do you want?
  댓글 수: 2
Stefania Maria
Stefania Maria 2019년 12월 10일
It still doesn't work.
I only need five points on the graphScreenshot (17).png
Star Strider
Star Strider 2019년 12월 10일
편집: Star Strider 2019년 12월 10일
Replace ‘[0,100]’ for the ‘tspan’ argument with:
tv = linspace(0, 100, 5);
Then use that in every ode45 call:
hold on
[t,x]=ode23(@h2, tv, [0,0]);
plot(x(:,1), x(:,2), 'kx')
[t,x]=ode23(@h2, tv, [-64,70]);
plot(x(:,1),x(:,2), 'bx')
[t,x]=ode23(@h2, tv, [-134,0]);
plot(x(:,1), x(:,2), 'kx')
[t,x]=ode23(@h2, tv, [55.4/2,70]);
plot(x(:,1), x(:,2), 'kx')
[t,x]=ode23(@h2, tv, [-323.4/2,70]);
plot(x(:,1), x(:,2), 'kx')
hold off
That will produce five points for every ode45 call.
If you only want five points total, you need to choose which points you want to plot.
That might require:
hold on
[t,x1]=ode23(@h2, tv, [0,0]);
plot(x1(end,1), x1(end,2), 'kx')
[t,x2]=ode23(@h2, tv, [-64,70]);
plot(x2(end,1),x2(end,2), 'bx')
[t,x3]=ode23(@h2, tv, [-134,0]);
plot(x3(end,1), x3(end,2), 'kx')
[t,x4]=ode23(@h2, tv, [55.4/2,70]);
plot(x4(end,1), x4(end,2), 'kx')
[t,x5]=ode23(@h2, tv, [-323.4/2,70]);
plot(x5(end,1), x5(end,2), 'kx')
hold off
Or something similar.
Experiment to get the result you want.

Community Treasure Hunt

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

Start Hunting!

Translated by