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.

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

1 Comment

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

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Asked:

on 19 Feb 2016

Commented:

on 19 Feb 2016

Community Treasure Hunt

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

Start Hunting!