필터 지우기
필터 지우기

help debugging my script?

조회 수: 1 (최근 30일)
Christopher Maraj
Christopher Maraj 2018년 3월 13일
편집: per isakson 2018년 3월 18일
This script is meant to solve a set of differential equations and return an output consisting of the quantities [T,X,Y,Z,U,V,W] in the form of a vector. When i run the code nothing appears, only the name of my m-file in the command window. Could someone help me find where in my code I've made a mistake?
  댓글 수: 3
Christopher Maraj
Christopher Maraj 2018년 3월 13일
편집: per isakson 2018년 3월 18일
the function was called using
[T,X,Y,Z,U,V,W] = satellite(Xo,Yo,Zo,Uo,Vo,Wo,tstart,tend,maxthrust)
.
G = 6.67408*10^-11;
Me = 5.97*10^24;
Re = 6.37*10^6;
m = 1500;
dt =1;
t = 1;
total = 0;
n = 1;
while n <= n-2
n = n +1;
[Xthrust, Ythrust, Zthrust] = engine(tstart, tend, maxthrust, t, u, v, w)
u(n+1) = u(n)*(Xthrust/m) -G*Me*(x(n)/((x(n).^2+y(n).^2+z(n).^2).^3/2))*dt;
v(n+1) = v(n)*(Ythrust/m) -G*Me*(y(n)/((x(n).^2+y(n).^2+z(n).^2).^3/2))*dt;
w(n+1) = w(n)*(Zthrust/m) -G*Me*(z(n)/((x(n).^2+y(n).^2+z(n).^2).^3/2))*dt;
x(n+1) = x(n) + u(n+1)*dt;
y(n+1) = y(n) + v(n+1)*dt;
z(n+1) = z(n) + w(n+1)*dt;
t(n+1) = t(n) + 1;
x=x(n+1)-x(n);
y=y(n+1)-y(n);
z=z(n+1)-z(n);
h = sqrt.(x^2 + y^2 + z^2) - Re;
Vmag = sqrt(u^2 + v^2 + w^2);
Acc = Vmag/dt;
n = n+1;
total = total + sqrt(x.^2 + y.^2 + z.^2);
if total > 4.2*10^8
break
end
end
end
% end function satellite
KSSV
KSSV 2018년 3월 13일
You need to check your while loop....the code is not executing while loop.

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

채택된 답변

Stephen23
Stephen23 2018년 3월 13일
편집: Stephen23 2018년 3월 13일
You wrote a while condition that will never be true. Have a look at this line:
while n <= n-2
For what values of n can this be true? Can you think of any real value of n where it is less than or equal to itself minus two? Try some real number examples, if you are not sure what is going on, e.g.:
n = 5
5 <= 5-2
5 <= 3
Is this ever going to be true?

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by