Nonlinear Optimization problem in Matlab

Hi
I hve problem when I use x(0) in nonlinear constraint in my code and I have to start with x(0)!.
Please, Could any one solve this issue. I have to solve it to find the lower and upper bounds.
Screen Shot 2019-03-06 at 10.07.31 PM.png
Screen Shot 2019-03-06 at 9.50.28 PM.png
THE ERROR:
Screen Shot 2019-03-06 at 10.03.23 PM.png

12 件のコメント

Torsten
Torsten 2019 年 3 月 7 日
1, Array indices start at 1; thus x(0) will produce an error.
2. Put [] around the c-vector.
Best wishes
Torsten.
Talal Alharbi
Talal Alharbi 2019 年 3 月 9 日
Thank you Torston
If I put c=[] That mean the ((inequality constraints c)) is empty and I use this constraint to effect on my optimization problem to give me different results.
Your suggestion it works but without use this constraint.
Stephan
Stephan 2019 年 3 月 9 日
What Torsten meant was not:
c=[]
but
c=[x(1)...]
Talal Alharbi
Talal Alharbi 2019 年 3 月 13 日
Thank you Stephan
I should start from x(0) since The first row from the matrix is [1 1 1 1 1 1 1 1 1 1]
So, I cannot start from x(1).
Torsten
Torsten 2019 年 3 月 13 日
編集済み: Torsten 2019 年 3 月 13 日
Shift all your x-indices by 1 - this will do the job:
objective = @(x) sum(x(2:end));
and
for i = 2:9
c(i-1,1) = x(i)^2-x(i-1)*x(i+1);
end
Talal Alharbi
Talal Alharbi 2019 年 3 月 14 日
Thank you Torsten . I appreciate it.
Actually,I did this way before. But I try to get other results when I start from x(0) since I want to compare them with other studing. NOW, I conclude, I cannot get results from this situation if I start from x(0).
My concern now is how can I find the upper bound from this problem?
I try to change the objective function by multiplying it (-1) but it did not work and I got this error.
Screen Shot 2019-03-14 at 2.06.05 AM.png
Torsten
Torsten 2019 年 3 月 14 日
It is impossible to load your screenshots into MATLAB.
So please include your complete code as plain text and use the CODE button to format it.
Talal Alharbi
Talal Alharbi 2019 年 4 月 10 日
I found the minimize, but I could not find the maximize for the same code, Could you help me, please?
Torsten
Torsten 2019 年 4 月 10 日
If you use
objective=@(x) -(x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8));
you maximize the expression
x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)
TALAL ALHARBI
TALAL ALHARBI 2019 年 4 月 10 日
Actually, I did but it does give me the different value.
Torsten
Torsten 2019 年 4 月 10 日
What do you mean by "different value" ? Different to what ?
Talal Alharbi
Talal Alharbi 2019 年 4 月 14 日
I attached the code. The problem when I try to find the upper bound (max) which after I multply by (-)Screen Shot 2019-04-14 at 3.09.01 PM.png

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

 採用された回答

David Wilson
David Wilson 2019 年 4 月 10 日

0 投票

Are you confusing x0, the start guess with x(0), which does not exist. In your constraint, you write x(0). If that is really what you want, then you need to roll your indices on by one. But somehow I doubt it. If you hadpasted your code, I'd have taken a look at it.

3 件のコメント

Talal Alharbi
Talal Alharbi 2019 年 4 月 14 日
x0 it is ok , there is no effect of it. But (the maximize) I could not find it when I change the obejctive function to negative.
Walter Roberson
Walter Roberson 2019 年 4 月 14 日
You assign the output of the first fmincon() call to a pair of variables named x and fmincon . When you do that, fmincon becomes a numeric scalar instead of a function, and the [x,fval] = fmincon(etc) that you have becomes a request to index into the scalar named fmincon and somehow return two different variables from that, which is not possible from an indexing operation.
Talal Alharbi
Talal Alharbi 2019 年 4 月 14 日
Ok, I got it. Thank you so much. :)

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

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by