Optimization problem on Constraint declaration

Hello,
I have a code
syms a wd;
c4_update=0.0248*abs(a)^4 - 9.878; %coming from some other equation
c3_update=abs(wd*(- 0.02+ a*(0.040 - 0.1352i)) + 0.223 - 0.223i)^2 + 0.223+ 0.223i)^2 + a*(0.096- 0.089i)) + 0.22 - 0.223i)^2 % coming from some other equation
nonlcon =@constraintfcn;
[x_value2,fval2] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon2,opts); % where fun,x0,A,b,Aeq,beq,lb,ub,opts are well defined
function [c,ceq] = constraintfcn(c3_update,c4_update)
c(1)= c3_update(1);
c(2)=c4_update(1);
ceq = [];
end
It gives error. How to solve this problem.

3 件のコメント

Matt J
Matt J 2020 年 11 月 18 日
It gives error.
An error you haven't shown us...
Soumili Sen
Soumili Sen 2020 年 11 月 18 日
It shows "FMINCON requires all values returned by functions to be of data type double."
Matt J
Matt J 2020 年 11 月 18 日
Yes, but you haven't copy/pasted the full error message, so we cannot see where the error is coming from.

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

 採用された回答

Matt J
Matt J 2020 年 11 月 18 日
編集済み: Matt J 2020 年 11 月 18 日

0 投票

We can't tell from your code what the relation is supposed to be between a, wd and x. This might be what you were trying to do, however:
nonlcon =@constraintfcn;
[x_value2,fval2] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon2,opts); % where fun,x0,A,b,Aeq,beq,lb,ub,opts are well defined
function [c,ceq] = constraintfcn(x)
a=x(1); wd=x(2);
c(1)= abs(wd*(- 0.02+ a*(0.040 - 0.1352i)) + 0.223 - 0.223i)^2 + 0.223+ 0.223i)^2 + a*(0.096- 0.089i)) + 0.22 - 0.223i)^2;
c(2)=0.0248*abs(a)^4 - 9.878;
ceq=[];
end

5 件のコメント

Soumili Sen
Soumili Sen 2020 年 11 月 19 日
ok understand. But one problem is that the values of c4_update and c3_update are random in nature (which is coming from other calculation) which I want as the input of the function. I can't define c(1) and c(2) like that,coz it will change for next calculation.
Matt J
Matt J 2020 年 11 月 19 日
For any fixed value of x, your constraint function constraintfcn(x) must return the same value all the time. The defintiion of the function is not allowed to evolve, stochastically or otherwise, throughout the optimization.
Soumili Sen
Soumili Sen 2020 年 11 月 19 日
ok. It's mean I can't use c4_update and c3_update as an input,right? I have to use a fixed value (like x)?
Matt J
Matt J 2020 年 11 月 19 日
編集済み: Matt J 2020 年 11 月 19 日
Both the constraint and objective functions must be a function of your unknown variable vector x (and nothing else). You can make the definition of the constraint function depend on other fixed problem parameters, however that definition must remain fixed throughout the optimization. During the optimization, the only thing that is allowed to vary the output of the constraint and objective functions are the different guesses for the unknowns that fmincon will iteratively pass in as input.
Soumili Sen
Soumili Sen 2020 年 11 月 19 日
Ok understand. Thank you for your valuable suggestions.

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

その他の回答 (0 件)

カテゴリ

質問済み:

2020 年 11 月 18 日

コメント済み:

2020 年 11 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by