What is wrong with my nonlinear equality?

1 回表示 (過去 30 日間)
Arif Ahmed
Arif Ahmed 2020 年 3 月 9 日
コメント済み: John D'Errico 2020 年 3 月 11 日
I try to run this code but I get the error:
Unable to perform assignment because dot indexing is not supported for variables of this type.
Error in fmincon (line 370)
options.DiffMinChange = optimget(options,'DiffMinChange',defaultopt,'fast',allDefaultOpts);
I think it is to do with my nonlinear equality function. Does the following look unfeasible for fmincon?
function [c,ceq] = nlcon(V)
global Y_act S_inj
c = [];
ceq = S_inj - diag(V(1:4))*diag(exp(1i*(V(5:end))))*conj(Y_act)*(V(1:4,1).*exp(1i*V(5:end,1)));
Update 10/03/2020
Thanks a lot. I have figured out the poblems. I just started with the optimization in MATLAB yesterday and so was not focusing on the inputs correctly.
  5 件のコメント
Walter Roberson
Walter Roberson 2020 年 3 月 10 日
We need to see your call to fmincon()
Arif Ahmed
Arif Ahmed 2020 年 3 月 10 日
Steven Lord: Thanks, I was indeed entering the nonlinear equality function in the wrong position.

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

回答 (1 件)

John D'Errico
John D'Errico 2020 年 3 月 9 日
編集済み: John D'Errico 2020 年 3 月 9 日
When you have a problem, the first thing you should do is to try to run your function, alone from the commandline. In fact, I often recommend that you do this no matter what, BEFORE you try any optimization. Can you evaluate the objective function? Do the same for the constraint function. Does it evaluate, and return something reasonable?
So, can you pass in a vector of unknowns into nonlcon? If it does run, then that is not your problem. If it does not run, then it will point out that line anyway.
If your function does indeed fail at that line, then you need to tell us what are the variables involved. That is, what are Y_act and S_inj? What class are they? What size is the array V? More importantly, what is the initial start point for V? Is V perhaps something in symbolic form, or perhaps a cell array? So what class is the thing that is in V?
Finally, I would ask what is the exact size and shape of V? For example, I would point out that unless V is a column vector of length EXACTLY 8, the code you show will never run at all. However, it looks like your code does not know that the length is 8, since you wrote 5:end, instead of 5:8 explicitly. That suggests you may want to run this code for longer unknown vectors sometimes.
My point is, the fragment:
(V(1:4,1).*exp(1i*V(5:end,1)))
cannot execute unless V is a column vector of length 8, but V is indexed as if it is an array or vector of unknown size.
Finally, I might ask if the array ceq is indeed complex as a result. That alone will be highly problematic for fmincon to run, althoiugh it would not cause the problem you saw. Even a tiny complex part in the least significant bits of the result will blow things out of the water.
  3 件のコメント
Walter Roberson
Walter Roberson 2020 年 3 月 11 日
It is usually more robust to split complex variables into a pair of variables, one for the real part and one for the imaginary part. That permits bounds to be put on them, whereas you cannot put bounds on complex-valued variables because comparison between complex-valued variables does strange things.
John D'Errico
John D'Errico 2020 年 3 月 11 日
Whether or not complex variables can be handled well is not pertinent to the problems you have, long before you ever need to worry about that. You need to worry about whether your code is even excutable first, and THEN worry about whether the optimization does what you want.

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by