Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

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 visualización (últimos 30 días)
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 comentario
Jan
Jan el 30 de Nov. de 2012
Please learn how to format code in this forum. Inserting a white line after each line of code reduces the readability too much.

Respuestas (1)

Richard
Richard el 29 de Nov. de 2012
Editada: Richard el 29 de Nov. de 2012
Try to put hold after the plot command:
plot(x,y);
hold on;
  1 comentario
Christopher
Christopher el 30 de Nov. de 2012
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