Question has been removed
이전 댓글 표시
Removed
댓글 수: 1
Original question by E RS retrieved from Bing Cache:
I can't solve this error
clear
G = 6.67408*10^-11;
M1 = 5.9722*10^24;
x1x = 5*10^6;
x1y = 0;
M2 = 3.3*10^24;
x2x = -12*10^6;
x2y = 0;
ft = 15000;
dt = 1;
t = 0:dt:ft;
V = zeros(1,length(t));
Vx = 0;
Vy = 7058.6;
Px = 13*10^6;
Py = 0;
r1x = 0;
r1y = 0;
r2x = 0;
r2y = 0;
while ft>=t;
r1x = Px - x1x;
r1y = Py - x1y;
r2x = Px - x2x;
r2y = Py - x2y;
r1mag = sqrt(r1x^2 + r1y^2);
r2mag = sqrt(r2x^2 + r2y^2);
ax = -G(((M1/r1mag^3)*r1x)+((M2/r2mag^3)*r2x));
ay = -G(((M1*r1y)/r1mag^3)+((M2*r2y)/r2mag^3));
Px = Px + Vx*dt;
Py = Py + Vy*dt;
Vx = Vx + ax*dt;
Vy = Vy + ay*dt;
plot(P);
end
That's my code an I keep getting the following error:
Index exceeds the number of array elements (1).
Error in AnotherTry (line 35)
ax = -G(((M1/r1mag^3)*r1x)+((M2/r2mag^3)*r2x));
How can I solve this?
Thanks.
p.s. If the V = zeros etc.. part looks odd, that's normal. I've been experimenting.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!