Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Hi, I'm trying to figure out why my script is only ploting the last input angle, not regarding any of the loops before it.

1 回表示 (過去 30 日間)
Christopher
Christopher 2012 年 11 月 29 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
function [ ] = odeSolver2()
tInc = input('Input desired timestep (in seconds)');
% Set initial conditions
Z = input('Input desired Landing distance (in meters)');
t(1)=0;
Ang1 = input('First angle of shooting (in degrees)');
Ang2 = input('Last angle of shooting (in degrees)');
AInc = input('Angle increment (also in degrees)');
Err = input('Acceptable Error (in meters)');
w = (Ang2-Ang1)/AInc;
IAng = linspace(Ang1,Ang2,w);
for n=1:w;
z(:,1,n) = VelocityforAngle(IAng(n));
end
i=1;
while z(3,i,n)>=0;
i=i+1;
t(i)=t(i-1)+tInc;
[z(:,i,n)] = oneStepRK(t(i-1), z(:,i-1,n), tInc);
end
j=1;
while abs(z(1,j)-Z)<=Err
j=j+1;
t(j)=t(j-1)+tInc;
[z(:,j,n)] = oneStepRK(t(j-1), z(:,j-1,n), tInc);
end
hold on figure(1);
plot(z(1,:),z(3,:))
xlabel('x')
ylabel('y')
axis ([0 12000 0 10000])
  1 件のコメント
Jan
Jan 2012 年 11 月 30 日
Please learn how to format code in this forum. Inserting a white line after each line of code reduces the readability too much.

回答 (1 件)

Richard
Richard 2012 年 11 月 29 日
編集済み: Richard 2012 年 11 月 29 日
Try to put hold after the plot command:
plot(x,y);
hold on;
  1 件のコメント
Christopher
Christopher 2012 年 11 月 30 日
Not really the issue, i had to rewrite some of it:
function [ ] = lolly()
tInc = input('Input desired timestep (in seconds)');
Z = input('Input desired Landing distance (in meters)');
t(1)=0;
Ang1 = input('First angle of shooting (in degrees)');
Ang2 = input('Last angle of shooting (in degrees)');
AInc = input('Angle increment (also in degrees)');
Err = input('Acceptable Error (in meters)');
w = (Ang2-Ang1)/AInc;
IAng = linspace(Ang1,Ang2,w);
for n=1:w;
z(:,1,n) = VelocityforAngle(IAng(n));
i=1;
while z(3,i,n)>=0;
i=i+1;
t(i)=t(i-1)+tInc;
[z(:,i,n)] = oneStepRK(t(i-1), z(:,i-1,n), tInc);
if abs(z(1,end,n)-Z)<=Err
hold on
figure(1)
plot(z(1,:),z(3,:))
xlabel('x')
ylabel('y')
axis ([0 12000 0 10000])
else
end
end
end

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by