我是新来使用Matlab,需要一些帮助来解决这个while循环。 我无法让while循环工作。我想循环继续,直到变量Velocity2> = - 20,但代码不停止运行。Matlab循环故障排除
功能
function [a] = acceleration(F,m,g) a=(F-m*g)/m;
function [v] = velocity(a,t,v0,t0) v=v0+a*(t-t0);
function [h] = height(a,t,h0,v0,t0) h=h0+v0*(t-t0)+(1/2)*a*(t-t0).^2;
代码
t0=0.15; % Initial time
dt=0.001; % Timesteps/Precision
v0=46.5285; % Initial velocity
h0=3.4896% Initial height
m=0.05; %Mass
g=9.81; % The gravitational constant
Velocity2=v0;
while Velocity2>=-20
t=t0+dt;
Velocity2=velocity(acceleration(0,m,g),t,v0,t0);
Height2=height(acceleration(0,m,g),t,h0,v0,t0);
end
它做到了,太感谢你了! – ErkNis 2013-04-24 16:46:45