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일)
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