Unable to run a simple 'fsolve' example.

Hi,
While running the root2d example file provided with the 'fsolve' document, MATLAB is throwing the following error:
Unrecognized function or variable 'eml_allow_mx_inputs'.
Error in fsolve
The code for root2d file is below and the m-file is placed in the MATLAB directory:
function F = root2d(x)
F(1) = exp(-exp(-(x(1)+x(2)))) - x(2)*(1+x(1)^2);
F(2) = x(1)*cos(x(2)) + x(2)*sin(x(1)) - 0.5;
end
I am running the following syntax to solve 'root2d':
fun = @root2d;
x0 = [0,0];
x = fsolve(fun,x0)

2 comentarios

Experiment with
restoredefaultpath; rehash toolboxcache
If that solves the problem then
savepath
Shiv Tewari
Shiv Tewari el 11 de Abr. de 2023
Thanks Walter. This syntax would come-in handy to fix any future path-related issues.

Iniciar sesión para comentar.

 Respuesta aceptada

My guess is that you accidentally added the toolbox/optim/eml directory under matlabroot to the MATLAB search path. If it is on the path, remove it from the path.
contains(path, "toolbox/optim/eml")
ans = logical
0
When you run the following command it should not list the fsolve.m file in toolbox/optim/eml. It should list the one in toolbox/optim/optim.
which -all fsolve
/MATLAB/toolbox/optim/optim/fsolve.m
The version of the file in toolbox/optim/eml is only used by MATLAB Coder when you generate C or C++ code from a function that calls fsolve.

1 comentario

Shiv Tewari
Shiv Tewari el 11 de Abr. de 2023
Editada: Shiv Tewari el 11 de Abr. de 2023
Thanks Steven.
I saw that MATLAB was using the p-file for solving 'root2d,' I didn't know that MATLAB uses the m-file for solving the non-linear equation. As you suggested, I removed the path to the p-file and that did the trick.
I wonder how the path to the p-file got added to my MATLAB, because I didn't have this issue while using 'fsolve' ealier.

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2021b

Etiquetas

Preguntada:

el 11 de Abr. de 2023

Comentada:

el 11 de Abr. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by