How do I evaluate variables from my function at the optimum value and get them in the workspace?

I call fmincon as follows: [theta_LL, Fval]=fmincon('LLobjnew', thetainit, [], [], [], [], lb, ub, @Nonlcon, optionsLL, data);
My function LLobjnew looks like this: function [LL, pr2] = LLobjnew(theta, data)
theta_LL has my optimum values. I output pr2 as above but it does not show up in the workspace. What I want to do is evaluate pr2 at the optimum values. Any way I can do this in the call to fmincon? Any way to do this at all? Pr2 is a matrix which is quite complicated, it depends on many of the parameters in theta in not so simple ways so I'm hoping to do this directly but anything that works.

Answers (1)

function [LL, pr2] = LLobjnew(theta, data)
means pr2 is the gradient of LL with respect to the theta variables.
In any case, as long as you have GradObj set to 'off' you won't have problems with fmincon treating this incorrectly. (I am assuming that pr2 is not really the gradient of LL.)
As to your question, after you have fmincon calculate theta_LL, can you run
[LL, pr2] = LLobjnew(theta_LL, data)
and get pr2 that way?
Alan Weiss
MATLAB mathematical toolbox documentation

1 Comment

Thanks for the response. I have set grad obj set to off: optionsLL = optimset('Display','iter', 'GradObj', 'off', 'Algorithm', 'interior-point', 'LargeScale','on', 'MaxFunEvals', 20000);
I have: [LL, pr2]=LLobjnew(theta_LL, data); just after fmin con.
It is returning pr2 to to the workspace but it's just a list of parameter names and no values.

This question is closed.

Asked:

on 6 Dec 2013

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!