# Help plotting a while loop

9 visualizaciones (últimos 30 días)
Mike Holbach el 3 de Mzo. de 2015
Comentada: rantunes el 3 de Mzo. de 2015
Hey guys, I'm having trouble with this while loop. The plot will not show up. Thanks in advance
clc, clear all
y=0;
x=0;
e=2.718;
while y<=9.8
y=y+(10*(1-e^(-x/4)))
x=x+1;
end
x=linspace(0,4,5);
plot(x,y)
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

rantunes el 3 de Mzo. de 2015
Hey,
Notice that you are always updating a new value of x and y at each iteration, so in the end you have not a pair of vectors with values but just one pair of values.
Maybe something more like this?
y(1) = 0;
x(1) = 0;
i = 1;
e=2.718;
while y <= 9.8
y(i+1) = y(i) + (10*(1-e^(-x(i)/4)));
x(i+1) = x(i) + 1;
i = i + 1;
end
plot(x,y)
Greets
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
rantunes el 3 de Mzo. de 2015
(just rephrasing a bit my first sentence. In the end you have one value for y and a row of values for x, due to the linspace, and I think is that what you dont want)

Iniciar sesión para comentar.

### Categorías

Más información sobre Annotations en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by