Thanks Johan for reply
I executed your code above and got this result:
??? Error using ==> optimizer.optimizer at 194
Failed exporting the model: Solver not found (+knitro)
I have trial version with license I verified it by this code:
[x fval] = knitromatlab(@(x)cos(x),1)
Final Statistics
----------------
Final objective value = -1.00000000000000e+000
Final feasibility error (abs / rel) = 0.00e+000 / 0.00e+000
Final optimality error (abs / rel) = 2.37e-009 / 2.37e-009
# of iterations = 7
# of CG iterations = 0
# of function evaluations = 12
# of gradient evaluations = 8
Total program time (secs) = 0.083 ( 0.063 CPU time)
Time spent in evaluations (secs) = 0.014
===============================================================================
x =
3.1416
fval =
-1.0000