Problem with plotting functions regarding a projectile motion

My problem is the plot of some functions which are based on a projectile motion. I wrote this code:
x0 = 0;
y0 = 0;
V=90;
g=9.81;
t=[0:0.01:20];
angle=[10; 25; 45; 65; 85];
x = V*cos(angle)*t + x0;
y = - g*t.^2/2 + V*sin(angle)*t + y0;
but at the end matlab tells me: 'Error using + Matrix dimension must agree'. I defined all variables, but i don´t understand why i can´t plot these functions.

Respuestas (1)

James Tursa
James Tursa el 19 de Feb. de 2016
Editada: James Tursa el 19 de Feb. de 2016
sin(angle) is a column vector, and t is a row vector, so sin(angle)*t will be a 2D matrix. But g*t.^2/2 will have the same dimensions of t which is a row vector. So you can't add them.
What are you trying to do? Are you trying to get multiple curves to plot (one curve for each angle), or somehow trying to get a single curve to plot from this? E.g., you could do this to add them but not knowing your intent I am not sure this is what you want:
y = bsxfun(@plus, -g*t.^2/2, V*sin(angle)*t + y0 );

1 comentario

Yes, i´am trying to get multiple curves to plot (one curve for each angle).

Iniciar sesión para comentar.

Categorías

Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 19 de Feb. de 2016

Comentada:

el 19 de Feb. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by