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!