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개)
James Tursa
2016년 2월 19일
편집: James Tursa
2016년 2월 19일
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!