Why does my script keep getting the Error using ./ Matrix dimensions must agree when calculating y in the script
이전 댓글 표시
my function
function [d,t,y_max] = fire_projectile(v,y0,theta)
%v is initial velocity
%y0 is launch height
%theta is launch angle
g=9.81;
d = ((v.*cos(theta))/g).*((v.*sin(theta))+((((v.*sin(theta)).^2)+(2.*g.*y0))).^0.5);
%d is the overall distance traveled
y_max = y0 + ((v.*sin(theta))/(2.*g));
%y_max is max height reached
t= d/(v.*cos(theta));
%time travelled
my script
clear
g=9.81; %value for gravity
v=input('input initial velocity ','s');
y0 = input('input launch height ','s');
theta=10;
[d,t,y_max] = fire_projectile(v,y0,theta);
x=0:1:d(1);
y = (x*tan(theta))-((g*(x.^2))./(2.*((v.*cos(theta)).^2)));
plot(y,x);
%y is the height at position x
i only get the error when inputs for v and y0 are greater than 10, which they need to be.
edit:
these are the 2 errors i get
Error using ./
Matrix dimensions must agree.
Error in fire_projectile_script (line 8)
y = (x*tan(theta))-((g*(x.^2))./(2.*((v.*cos(theta)).^2)));
outputs seen in workspace
d: [-60.5,-58.2]
g: 9.81
t: 1.43
y_max: [47.6, 46.7]
댓글 수: 8
madhan ravi
2018년 11월 14일
after running the code type d in command window and see the mistake you made , why do you people always supress the output?
henry mulligan
2018년 11월 14일
madhan ravi
2018년 11월 14일
Type
0 : 1 : -60.5
in command window
henry mulligan
2018년 11월 14일
madhan ravi
2018년 11월 14일
it relates to the below code:
x=0:1:d(1);
henry mulligan
2018년 11월 14일
madhan ravi
2018년 11월 14일
편집: madhan ravi
2018년 11월 14일
can you organise your code and provide all the necessary datas(v,y0,theta) to test your code?
henry mulligan
2018년 11월 14일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!