I am calling outside functions for this code, but when I am getting an error saying I have too many output arguments. I think the error is within my function LandingDistance

1 次查看(过去 30 天)
%% problem 2
% user-defined function to compute the horizontal distance
% traveled by a projectile knowing the launch angle, the initial velocity,
% and geometric parameters defining the initial coordinates of the projectile.
d1 = 0.0876;
d2 = 0.1190;
v0 = 3.2;
thetaL = 50;
g = 9.81; % gravitational acceleration in m/s^2
% call initial coords function and initial velocity function
[x0, y0] = InitialCoords(d1, d2, thetaL); % input units: m, m, degrees, output units: m
[v0x, v0y] = InitialVelocityComponents(v0, thetaL); % input units: m/s de,grees, output units: m/s
%Solve the y equation for tLand by calling your Quadratic function.
a = -0.5*g; % g = acceleration due to gravity in m/s^2
b = v0y; % initial velocity in y direction
c = y0; % initial y position
plusOrMinus = -1;
root = Quadratic(a, b, c, plusOrMinus); % neg root
tLand = root;
% plug tLand into the x eqn to get xLand
xLand = LandingDistance(d1, d2, v0, thetaL);
fprintf('For launch angle = %.1f degrees and v0 = %.1f m/s, the landing distance is %.2f m \n', thetaL, v0, xLand)
Error using LandingDistance
Too many output arguments.
Error in HW3_projectile (line 36)
xLand = LandingDistance(d1, d2, v0, thetaL);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_____________________________________
function code
% landing distance function
function LandingDistance(d1, d2, v0, thetaL)
% x_Land --> the horizontal distance traveled by the projectile
g = 9.81; % gravitational acceleration in m/s^2
[x0, y0] = InitialCoords(d1, d2, thetaL) % input units: m, m, degrees, output units: m
[v0x, v0y] = InitialVelocityComponents(v0, thetaL) % input units: m/s de,grees, output units: m/s
a = -0.5*g; % g = acceleration due to gravity in m/s^2
b = v0y; % initial velocity in y direction
c = y0; % initial y position
plusOrMinus = -1;
[root] = Quadratic(a, b, c, plusOrMinus); % neg root
tLand = root
xLand = x0 + (v0x*tLand)
end
Not enough input arguments.
Error in LandingDistance (line 6)
[x0, y0] = InitialCoords(d1, d2, thetaL)
^^
>>

回答(1 个)

Star Strider
Star Strider 2025-1-27
编辑:Star Strider 2025-1-27
The reason is that ‘LandingDistance’ doesn’t return any outputs:
function LandingDistance(d1, d2, v0, thetaL)
You probably want it to be:
function xLand = LandingDistance(d1, d2, v0, thetaL)
If so, that should work.
.
EDIT — Corrected typographical errors.
  5 个评论
ERIN
ERIN 2025-1-27
I was missing an equation that needed a, b, and c. basically I was leaving out an equation and had variables assigned after calling functions instead of before

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Linear Least Squares 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by