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