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))));

추가 답변 (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