Why does my script keep getting the Error using ./ Matrix dimensions must agree when calculating y in the script
Ältere Kommentare anzeigen
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 Kommentare
madhan ravi
am 14 Nov. 2018
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
am 14 Nov. 2018
madhan ravi
am 14 Nov. 2018
Type
0 : 1 : -60.5
in command window
henry mulligan
am 14 Nov. 2018
madhan ravi
am 14 Nov. 2018
it relates to the below code:
x=0:1:d(1);
henry mulligan
am 14 Nov. 2018
madhan ravi
am 14 Nov. 2018
Bearbeitet: madhan ravi
am 14 Nov. 2018
can you organise your code and provide all the necessary datas(v,y0,theta) to test your code?
henry mulligan
am 14 Nov. 2018
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Programming 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!