I am getting the function unrecognized, how to solve this problem

%% define parameter and the initial conditions
param.g = 9.81;
param.kappa = 0.006;
u0 = 35*cos(pi/4);
v0 = 35*sin(pi/4);
%% setting up the variable
x0 = [0; 0;
u0; v0];
tspan = [0 20];
[tout, xout] = ode45(ballTrajectoryFun, tspan, x0, [], param);
%% displaying the results
figure(1);
plot(xout(:,1),xout(:,2),'bo');
xlable('x(m)'); ylable('y(m)');
%% animating results
exitCode = ballAnimtion(tout,xout);
Unrecognized function or variable
'ballTrajectoryFun'.
code is upto exitcode, rest two lines are error

4 Comments

"Unrecognized function or variable 'ballTrajectoryFun'."
Do you have a function named "ballTrajectoryFun" ? Did you either write one yourself or get given one ?
To add to the question of @Stephen23 I would ask if you DO think you have that function, where did you place it? In which directory does it reside, and is that directory on your search path? Did you place it in one of the MathWorks supplied directories? That would be a bad idea.
To add to both @Stephen23 and @John D'Errico -- the argument to ode45 must be a function handle, not the function reference itself --
[tout, xout] = ode45(@ballTrajectoryFun, tspan, x0, [], param);
Note the '@' to create the handle to the function, not try to evaluate the function itself.
The function m-file location will still have to be on the search path, of course...
It is not impossible that there was a prior section of code along the lines of
ballTrajectoryFun = @ballTrajectory;
The first parameter to ode45 must, according to current documentation, resolve to a function handle. Potentially that could be a variable that stored a function handle, or a call to a function that returned a function handle, or a function handle constructor.
It is not longer documented, but for backwards compatibility, the first parameter to ode45() can also resolve to a character vector or string array scalar, that is the name of a top-level function ( not of a local or private or nested function) or the name of a simulink model (though it would be difficult to get simulink models to match the right calling sequence.)

Sign in to comment.

Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Asked:

on 28 Feb 2026 at 4:52

Commented:

on 1 Mar 2026 at 0:40

Community Treasure Hunt

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

Start Hunting!