??? Error using ==> evalin Undefined function or method 'arctan' for input arguments of type 'double'.

8 views (last 30 days)
I'm trying to figure out why I keep getting the error:
??? Error using ==> evalin Undefined function or method 'arctan' for input arguments of type 'double'.
I'm trying to optimize a large function with symbolic variables in it using Hessian and gradient matrices and multidimensional Newton optimization techniques (namely, x1=x0-(H(x0))^-1)*grad(f(x0))).
That error crops up at different points in running. Sometimes it happens after the first iteration; other times, it happens after 3 or 4 runs through.
The objective function is: (T-atan(((Py+Vy*k)-Psy)/((Px+Vx*k)-Psx)); where Px, Vx, Py, and Vy are the symbolic variables that are in need of optimization. The others have values being assigned to them already. The command jacobian is used to find the gradient, and then applied again to acquire the Hessian. The Hessian and Jacobian are summed 30 times with varying numbers to form a large expression. An appropriate initial guess is being used. The eval command is being used to compute the gradient and Hessian matrices with values subbed in.
Any ideas on why this error keeps occurring?
  2 Comments
Sean de Wolski
Sean de Wolski on 2 Dec 2011
What is the string you're feeding evalin? This is why the use of evalin/eval/assignin bis recommended against because bugs are hard to catch.
Are you sure you don't have 'arctan' instead of 'atan' somewhere?
Mike E.
Mike E. on 2 Dec 2011
No arctans have made it through, to the best of my knowledge. All outputs at any stage have, at worst, atan(x), where x is some fractional number.
What's being passed to the eval command is: H(1,:)=eval(H_half(1,:))+H(1,:); where H_half is the Hessian matrix unevaluated (ie. 1804741876787401/549755813888 * atan(2/13), etc.) and H is the destination matrix of the computed entries in the H_half matrix.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 2 Dec 2011
You should not use evalin() to do substitutions in symbolic expressions. Use subs() instead, or use matlabFunction to convert to a non-symbolic function handle that can then be executed with numeric arguments.
The symbolic arc tangent in MuPAD is arctan() and that is what is going to be in the character vector, as displaying a symbolic expression displays the MuPAD expression without converting it to any MATLAB routine names. It was never intended that eval'ing a MuPAD expression at the MATLAB level would necessarily be meaningful.
  3 Comments
Mike E.
Mike E. on 2 Dec 2011
Subs was used to replace all the symbolic variables with their respective values. The problem is, it left me with a mess of giant numbers and unevaluated atan instances (ie. atan(2/13), atan(85/98), etc.). Eval is what the TA I spoke with regarding an earlier issue (incredibly large statement of numbers and inverse tangents not being calculated) recommended I use for making the expression usable.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!