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.

回答(1 个)

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

类别

帮助中心File Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by