Hi everybody, I'm trying to use fmincon for solving an optimization problem with 3 variables that have to be optimized. This is basically my code:
J = @(rR, rG, rB) sum(abs(X_ref-optimization_values(rR, rG, rB)));
initial_guess= [refR; refG; refB];
[rR_opt, rG_opt, rB_opt] = fmincon(J,initial_guess,[],[]);
But I always get the following error: </matlabcentral/answers/uploaded_files/65918/Capture.PNG>
My code works perfectly if I only use one variable for the optimization. Are 3 variables not possible with fmincon? or is my syntax wrong?
Thanks and Merry Christmas to everyone!

 採用された回答

John D'Errico
John D'Errico 2016 年 12 月 20 日
編集済み: John D'Errico 2016 年 12 月 20 日

1 投票

You passed in a vector of initial guess. But then somehow, you expect fmincon to magically know how to interpret and split that apart into THREE different inputs to your function. How should it know how to apportion your unknowns? Unless of course, you have the mind-reading toolbox, which is still in beta test for many years.
The function J must take a VECTOR of length 3. Nothing stops you from splitting it apart yourself though, inside the function call, or like this:
J = @(rRGB) sum(abs(X_ref-optimization_values(rRGB(1),rRGB(2),rRGB(3))));

1 件のコメント

Aensche
Aensche 2016 年 12 月 20 日
Thanks alot, that worked :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

2016 年 12 月 20 日

コメント済み:

2016 年 12 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by