use of fminunc with more than one variables

10 views (last 30 days)
rahul
rahul on 5 Apr 2019
Answered: Alan Weiss on 5 Apr 2019
I am working to solve an uncostraint non-linear optimization using 'fminunc'
there are two versions
1.using a vector for different variables
>> fminunc(@(x)(x(1)-x(2)^0.4)/x(1), [1,2])
Solver stopped prematurely.
fminunc stopped because it exceeded the function evaluation limit,
options.MaxFunctionEvaluations = 200 (the default value).
ans =
1 2
2. using different variables
>> fminunc(@(x1,x2)(x1-x2^0.4)/x1, 1,2, 'options')
Unable to perform assignment because dot indexing is not supported for variables of this type.
Error in createOptionFeedback (line 33)
options.(stopTestOptions{k}) = [];
Error in prepareOptionsForSolver (line 57)
optionFeedback = createOptionFeedback(options);
Error in fminunc (line 156)
[options, optionFeedback] = prepareOptionsForSolver(options, 'fminunc');
As you can observe, the 1st version works, whereas 2nd fails.
What is the reason for this error, Is there way to make work the 2nd version ?
Thanks,
best regards,
Rahul

Answers (1)

Alan Weiss
Alan Weiss on 5 Apr 2019
Please see the documentation on writing scalar objective functions.
If you have Release 2019a, you can also use the problem-based workflow, which would allow you to use two different control variables.
Alan Weiss
MATLAB mathematical toolbox documentation

Community Treasure Hunt

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

Start Hunting!