MATLAB: Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.

error in fmincon (line 601)

if I use following script
z = @(x)(0.78000000000e11 + 0.2000000000e10 * sind(x(2))) * ...
(0.11e2 + 0.5e0 * sind(x(1))) / ...
(0.67e2 / 0.4000000e7 + sind(x(1)) / 0.4000000e7) / ...
(0.6e1 + sind(x(1))) / 0.2e1 + (0.78000000000e11 + 0.2000000000e10 * sind(x(2))) * ...
(0.11e2 + 0.5e0 * sind(x(1))) / (0.6e1 + sind(x(1))) / (0.67e2 / 0.8000000e7 + sind(x(1)) ...
/ 0.8000000e7) / 0.2e1 + (0.78000000000e11 + 0.2000000000e10 * sind(x(2))) * ...
(0.10e2 + 0.5e0 * sind(x(1))) / (0.67e2 / 0.4000000e7 + sind(x(1)) / 0.4000000e7) / ...
(0.12e2 + sind(x(1))) / 0.2e1 + sqrt((0.78000000000e11 + 0.2000000000e10 * sind(x(2))) * ...
(0.11e2 + 0.5e0 * sind(x(1))) ^ 2 / (0.67e2 / 0.4000000e7 + sind(x(1)) / 0.4000000e7) ^ 2 + ...
0.2e1 * (0.78000000000e11 + 0.2000000000e10 * sind(x(2))) * (0.11e2 + 0.5e0 * sind(x(1))) ^ 2 ...
/ (0.67e2 / 0.4000000e7 + sind(x(1)) / 0.4000000e7) / (0.6e1 + sind(x(1))) ^ 2 / ...
(0.67e2 / 0.8000000e7 + sind(x(1)) / 0.8000000e7) + ...
0.2e1 * (0.78000000000e11 + 0.2000000000e10 * sind(x(2))) * ...
(0.11e2 + 0.5e0 * sind(x(1))) * (0.10e2 + 0.5e0 * sind(x(1))) ...
/ (0.67e2 / 0.4000000e7 + sind(x(1)) / 0.4000000e7) ^ 2 / (0.12e2 + sind(x(1))) / ...
(0.6e1 + sind(x(1))) + (0.78000000000e11 + 0.2000000000e10 * sind(x(2))) * ...
(0.11e2 + 0.5e0 * sind(x(1))) ^ 2 / (0.6e1 + sind(x(1))) ^ 2 / ...
(0.67e2 / 0.8000000e7 + sind(x(1)) / 0.8000000e7) ^ 2 - 0.2e1 * ...
(0.78000000000e11 + 0.2000000000e10 * sind(x(2))) * (0.11e2 + 0.5e0 * sind(x(1))) * ...
(0.10e2 + 0.5e0 * sind(x(1))) / (0.67e2 / 0.4000000e7 + sind(x(1)) / 0.4000000e7) / ...
(0.12e2 + sind(x(1))) / (0.6e1 + sind(x(1))) / ...
(0.67e2 / 0.8000000e7 + sind(x(1)) / 0.8000000e7) + ...
(0.78000000000e11 + 0.2000000000e10 * sind(x(2))) * ...
(0.10e2 + 0.5e0 * sind(x(1))) ^ 2 / (0.67e2 / 0.4000000e7 + sind(x(1)) / 0.4000000e7) ^ 2 ...
/ (0.12e2 + sind(x(1))) ^ 2) / 0.2e1;
% Set up fmincon's options

x0 = [0 -0];
lb = [-90 -90];
ub = [90 90];
problem = createOptimProblem('fmincon','objective', ...
@(x) z(x),'x0',x0,'lb',lb,'ub',ub);
% Call fmincon
[xlocal,fvallocal] = fmincon(problem)
I will get output
xlocal =
90 -90
fvallocal =
1.2822e+016
However, if I make myfum.m file with following function
function f = myfun(x)
f = (0.78000000000e11 + 0.2000000000e10 * sind(x(2))) * ...
(0.11e2 + 0.5e0 * sind(x(1))) / ...
(0.67e2 / 0.4000000e7 + sind(x(1)) / 0.4000000e7) / ...
(0.6e1 + sind(x(1))) / 0.2e1 + (0.78000000000e11 + 0.2000000000e10 * sind(x(2))) * ...
(0.11e2 + 0.5e0 * sind(x(1))) / (0.6e1 + sind(x(1))) / (0.67e2 / 0.8000000e7 + sind(x(1)) ...
/ 0.8000000e7) / 0.2e1 + (0.78000000000e11 + 0.2000000000e10 * sind(x(2))) * ...
(0.10e2 + 0.5e0 * sind(x(1))) / (0.67e2 / 0.4000000e7 + sind(x(1)) / 0.4000000e7) / ...
(0.12e2 + sind(x(1))) / 0.2e1 + sqrt((0.78000000000e11 + 0.2000000000e10 * sind(x(2))) * ...
(0.11e2 + 0.5e0 * sind(x(1))) ^ 2 / (0.67e2 / 0.4000000e7 + sind(x(1)) / 0.4000000e7) ^ 2 + ...
0.2e1 * (0.78000000000e11 + 0.2000000000e10 * sind(x(2))) * (0.11e2 + 0.5e0 * sind(x(1))) ^ 2 ...
/ (0.67e2 / 0.4000000e7 + sind(x(1)) / 0.4000000e7) / (0.6e1 + sind(x(1))) ^ 2 / ...
(0.67e2 / 0.8000000e7 + sind(x(1)) / 0.8000000e7) + ...
0.2e1 * (0.78000000000e11 + 0.2000000000e10 * sind(x(2))) * ...
(0.11e2 + 0.5e0 * sind(x(1))) * (0.10e2 + 0.5e0 * sind(x(1))) ...
/ (0.67e2 / 0.4000000e7 + sind(x(1)) / 0.4000000e7) ^ 2 / (0.12e2 + sind(x(1))) / ...
(0.6e1 + sind(x(1))) + (0.78000000000e11 + 0.2000000000e10 * sind(x(2))) * ...
(0.11e2 + 0.5e0 * sind(x(1))) ^ 2 / (0.6e1 + sind(x(1))) ^ 2 / ...
(0.67e2 / 0.8000000e7 + sind(x(1)) / 0.8000000e7) ^ 2 - 0.2e1 * ...
(0.78000000000e11 + 0.2000000000e10 * sind(x(2))) * (0.11e2 + 0.5e0 * sind(x(1))) * ...
(0.10e2 + 0.5e0 * sind(x(1))) / (0.67e2 / 0.4000000e7 + sind(x(1)) / 0.4000000e7) / ...
(0.12e2 + sind(x(1))) / (0.6e1 + sind(x(1))) / ...
(0.67e2 / 0.8000000e7 + sind(x(1)) / 0.8000000e7) + ...
(0.78000000000e11 + 0.2000000000e10 * sind(x(2))) * ...
(0.10e2 + 0.5e0 * sind(x(1))) ^ 2 / (0.67e2 / 0.4000000e7 + sind(x(1)) / 0.4000000e7) ^ 2 ...
/ (0.12e2 + sind(x(1))) ^ 2) / 0.2e1;
end
now I make another script to call function and use fmincon function to find out minimum
% Set up fmincon's options
x0 = [0 0];
lb = [-90 -90];
ub = [90 90];
% Set up fmincon
fun = @myfun;
[x, fval] = fmincon(fun,x0,[],[],[],[],lb,ub)
I am getting error messages as follow:
Error in fmincon (line 601)
initVals.f = feval(funfcn{3},X,varargin{:});
Error in DrElishakoff7 (line 9)
[x, fval] = fmincon(fun,x0,[],[],[],[],lb,ub)
Caused by:
Failure in initial user-supplied objective function evaluation. FMINCON cannot
continue.
can please anyone help me to understand this phenomenon , I mean such strange behavior of compiler
I am getting the answers through another approach, it just that I can not understand why it is giving me error message.
can anyone please point out what's wrong ?
I am kinda new to Matlab as well as the Matlab community.

Best Answer

Thank you very much Walter Roberson, Kye Taylor and Matt J. for such a quick response.
I found out what was missing.
I was not calling function properly.
instead of using following script to call the function
% Set up fmincon's options

x0 = [0 0];
lb = [-90 -90];
ub = [90 90];
% Set up fmincon

fun = @myfun;
[x, fval] = fmincon(fun,x0,[],[],[],[],lb,ub)
Now, the new corrected script is as follow:
% Set up fmincon's options
x0 = [0 0];
lb = [-90 -90];
ub = [90 90];
% Set up fmincon
[x, fval] = fmincon(@(x) myfun(x),x0,[],[],[],[],lb,ub)
by using the new script, I am able verify my answer with Maple calculations.
Thanks again Walter Roberson, Kye Taylor and Matt J for your time and valuable inputs.