Hello people, I need some help with the error below:
Error using SpringendBallsB04>groundHeight
Too many output arguments.
Error in SpringendBallsB04>impactMap (line ...)
[~,groundSlope] = groundHeight(horizPos);
Error in SpringendBallsB04 (line ...)
[IC, ballRolling]= impactMap(impactState,P); %This becomes the new start state
HERE IS A PART OF THE PROGRAM. THE FUNKTION CALLED impactMap BELOW THE MAIN CODE MIGHT BE THE PROBLEM.
I AM TRYING TO MAKE A 3D SIMULATION OUT OF A 2D CODE
PLEASE HELP ME
[code attached as a file by Madhan Ravi since it was too long]

Réponses (1)

Srivardhan Gadila
Srivardhan Gadila le 11 Avr 2020

0 votes

The function z = groundHeight(x,y) in line 314 has only one output argument z and two input arguments x & y. You are calling this function in line 379 inside the function [stateOut, ballRolling] = impactMap(stateIn,P) as
[~,groundSlope] = groundHeight(horizPos);
Change it to
groundSlope = groundHeight(horizPos,2ndInputArgument);

5 commentaires

Jacob O. Otasowie
Jacob O. Otasowie le 11 Avr 2020
Thank you very much. It helped.
I still have other issues though. I have attached the file. Here is the current error:
Error using odearguments (line 95)
@(T,X)BALL_DYNAMICS(T,X,P) returns a vector of length 4, but the length of initial conditions vector is 6. The vector returned by
@(T,X)BALL_DYNAMICS(T,X,P) and the initial conditions vector must have the same number of elements.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in Ball (line 30)
sol = ode45(dynFunc,Tspan,IC,P.Options); %events defined in Options
Jacob O. Otasowie
Jacob O. Otasowie le 11 Avr 2020
Here is an excerpt from the directly affected part of the programm.
%% dynFunc = @(t,X,Y)Ball_Dynamics(t,X,Y,P); %Handle for the dynamics function
dynFunc = @(t,X)Ball_Dynamics(t,X,P); %Handle for the dynamics function
TermCond = 'Termination Condition: Max Bounces'; %For display only
%Loop through each section of the trajectory
for bounceNum=1:maxBounce
%% Run the dynamics until bounce or out of time
Tspan = [tNow,tEnd];
sol = ode45(dynFunc,Tspan,IC,P.Options); %events defined in Options
%% Store the state immediately before the collision
impactState = sol.y(:,end);
%% Solve the collision
[IC, ballRolling]= impactMap(impactState,P); %This becomes the new start state
tNow = sol.x(end); %Grab the last time
Trajectory{bounceNum}=sol; %Store the output of ode45
%% Check exit condition
if tEnd <= tNow
TermCond = 'Termination Condition: Max Time';
break
elseif ballRolling
TermCond = 'Termination Condition: Ball started rolling';
break
end
end
Srivardhan Gadila
Srivardhan Gadila le 21 Avr 2020
@Jacob O. Otasowie, I think the error is self explanatory. Refer to y0 Input Argument explanation of the function ode45. It states that "Initial conditions, specified as a vector. y0 must be the same length as the vector output of odefun, so that y0 contains an initial condition for each equation defined in odefun." So make sure that the initial condition IC and the output of the function dynFunc are of same length.
Jacob O. Otasowie
Jacob O. Otasowie le 22 Avr 2020

Connectez-vous pour commenter.

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Produits

Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by