Plotting ordered pairs.

조회 수: 7 (최근 30일)
Edward Steen
Edward Steen 2015년 11월 26일
답변: Star Strider 2015년 11월 26일
I want to plot x(i) and y(i) as ordered pairs, but am having difficulty doing this. Below is the code of the recursive for loop I'm using.
r(1)=1;
x(1)=1;
y(1)=0;
vx(1)=0;
vy(1)=2*pi;
dt=.002;
for i=2:400
r(i)=r(i-1);
vx(i)=vx(i-1)-(4*pi^2*x(i-1)/r(i)^3)*dt;
x(i)=x(i-1)+vx(i)*dt;
vy(i)=vy(i-1)-(4*pi^2*y(i-1)/r(i)^3)*dt;
y(i)=y(i-1)+vy(i)*dt;
end
Can anyone help?
  댓글 수: 1
Thorsten
Thorsten 2015년 11월 26일
So what's the problem?

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

채택된 답변

Star Strider
Star Strider 2015년 11월 26일
All you need to do is to add this code after your loop:
figure(1)
plot(x, y)
grid
axis equal
to get this plot:

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by