Plotting Issues with function provided

1 visualización (últimos 30 días)
N/A
N/A el 5 de Mzo. de 2020
Respondida: Walter Roberson el 6 de Mzo. de 2020
Attemtping to plot a graph of the equation displayed below. All I see is a line, where it should be more of a parabola.
g=9.81;
z0=100;
v0=55;
m=80;
c=15;
for t=0:.1:20
z=z0+(m/c)*(v0+(m*g/c))*1-exp(-c*t/m)-m*g*t/c;
end
plot(t,z)

Respuesta aceptada

Walter Roberson
Walter Roberson el 6 de Mzo. de 2020
Every iteration, you are overwriting all of z.
Also, with a for loop, each iteration, the loop control variable t will be assigned exactly one column (so, in context, a scalar). At the end of the loop, the loop control variable will be left as the last value it was assigned -- so in context, the scalar 20.
You are therefor asking asking to plot with a scalar t value and a scalar z value, which would only produce a dot at most (and usually not even that if you have not defined a marker type)
You should vectorize your computation.
The result will still look like a line. If you want something more like a parabola, you should plot between roughly t = -50 to +50 . The peak is at roughly -30

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by