Problem with plotting functions regarding a projectile motion
Ältere Kommentare anzeigen
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.
Antworten (1)
James Tursa
am 19 Feb. 2016
Bearbeitet: James Tursa
am 19 Feb. 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 Kommentar
Andreas Wojczik
am 19 Feb. 2016
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!