I am getting the function unrecognized, how to solve this problem
Show older comments
%% 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
Stephen23
on 28 Feb 2026 at 6:29
"Unrecognized function or variable 'ballTrajectoryFun'."
Do you have a function named "ballTrajectoryFun" ? Did you either write one yourself or get given one ?
John D'Errico
on 28 Feb 2026 at 13:34
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...
Walter Roberson
about 2 hours ago
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.)
Answers (0)
Categories
Find more on Simulink Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!