Finding Extremum of Multivariate Functions
Show older comments
I tried to use the fmincon function to find the extremum of the multivariate function, but it didn't work.Here is my question:
There are 10 variables:x1,x2,x3,x4,x5,x6,x7,x8,x9,x10, and 5 constants with values taken from the interval [-1, 1]: R(1,2), R(1,3), R(2,2), R(2,3), R(3,3).
There are the following relationships among these 10 variables: R(1,2)^2+x1^2+x3^2+x4^2=1; R(1,3)^2+x2^2+x5^2+x6^2=1; R(1,2)^2*x1^2=x3^2*x4^2; R(1,3)^2*x2^2=x5^2*x6^2; x7^2+x8^2=1;x9^+x10^2=1; R(2,2)*x3*x5*x7+R(2,2)*x4*x6*x9-R(2,3)*R(2,2)^2+R(2,2)*x1*x2*(x7*x9-x8*x10)=0; x3*x5*x8+x4*x6*x10+x1*x2*(x8*x9+x7*x10)=0.
The objective function is:R(2,3)^2*x1^2/R(3,3)^2/R(2,2)^2-2*R(2,3)*x1*x2/R(2,2)/R(3,3)^2*(x7*x9-x8*x10)+x2^2/R(3,3)^2.
The objective is to find the maximum value of the objective function.
It is observed that by solving the first 8 equations, x3, x4, x5, x6, x7, x8, x9, and x10 can be expressed as functions of x1 and x2 (the expressions may be very complicated), thus transforming the problem into an unconstrained extremum problem of a function of two variables x1 and x2.
I have been stuck on this problem for a few days. Specifically, I have not made any progress on how to obtain a specific solution through MATLAB or other mathematical software when R(1,2)=0.7844, R(1,3)=0.7844, R(2,2)=0.6202, R(2,3)=-0.2021, and R(3,3)=0.5864. I would be very grateful if anyone could give me some guidance.
Supplement: to use the fmincon function, the following code is used to input the objective function: fun = @(x) (x(1) - 2)^2 + (x(2) - 3)^2; I encountered difficulties with this step because the expression for the objective function for my problem was very complex, and it was not possible for me to manually enter it one by one. However, the variables in this code must, in my understanding, be in the form of x(1), x(2), but x(1), x(2) cannot be defined as symbolic variables using the syms command. So I thought of using the subs command. I plan to do the following: first, use the [x7, x8, x9, x10] = solve('R(2,2)x(5)x(3)x7+R(2,2)x(4)x(6)x9-R(2,3)R(2,2)^2+R(2,2)x(1)x(2)(x7x9-x8x10)=0','x(3)x(5)x8+x(4)x(6)x10+x(1)x(2)(x8x9+x7x10)=0','x7^2+x8^2=1','x9^2+x10^2=1','x7,x8,x9,x10') command to express x7, x8, x9, x10 as functions of x(1), x(2), x(3), x(4), x(5), x(6), and know that: x(3)=(1/2 - R(1,2)^2/2 - x(1)^2/2 + (-(R(1,2) + x(1) - 1)(R(1,2) + x(1) + 1)(R(1,2) - x(1) + 1)(x(1) - R(1,2) + 1))^(1/2)/2)^(1/2)
x(4)=(1/2 - R(1,2)^2/2 - x(1)^2/2 - (-(R(1,2) + x(1) - 1)(R(1,2) + x(1) + 1)(R(1,2) - x(1) + 1)(x(1) - R(1,2) + 1))^(1/2)/2)^(1/2)
x(5)=(1/2 - R(1,3)^2/2 - x(2)^2/2 + (-(R(1,3) + x(2) - 1)(R(1,3) + x(2) + 1)(R(1,3) - x(2) + 1)(x(2) - R(1,3) + 1))^(1/2)/2)^(1/2)
x(6)=(1/2 - R(1,3)^2/2 - x(2)^2/2 - (-(R(1,3) + x(2) - 1)(R(1,3) + x(2) + 1)(R(1,3) - x(2) + 1)(x(2) - R(1,3) + 1))^(1/2)/2)^(1/2)
Then use the command R(2,2)=0.6202,R(2,3)=-0.2021,R(1,2)=0.7844,R(1,3)=0.7844 to determine the values of the constants R(2,2), etc.
Finally, input the code fun = @(x) -0.2021^2x(1)^2/0.5864^2/0.6202^2+2-0.2021x(1)x(2)/0.6202/0.5864^2(subs(x7(1),{x(3),x(4),x(5),x(6)},{expression for x3 as a function of x(1), x(2), x(4) , x(5) , x(6) })*subs(x9(1),{x(3),x(4),x(5),x(6)},{x(3) , x(5) , x(6) }) - subs(x8(1),{x(3),x(4),x(5),x(6)},{x(3), x(4) , x(5) , x(6)})*(subs(x10(1),{x(3),x(4),x(5),x(6)},{x(3) , x(4) , x(5) , x(6) })) -x(2)^2/0.5864^2(To seek the maximum value of the objective function but using fmincon to find its minimum value, a negative sign is added to the objective function, where x7, x8, x9, and x10 are all 2-dimensional column vectors)
>> A = [];
>> b = [];
>> Aeq = [];
>> beq = [];
>> lb = [0, 0];
>> ub = [1, 1];
>> x0 = [0.2156, 0.2156];
>> [x_min, fval] = fmincon(fun, x0, A, b, Aeq, beq, lb, ub)
Run-time error message:
Error in
@(x) expression... ...
Error in fmincon (line 601)
initVals.f = feval(funfcn{3},X,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.
So I think the error should be in the code line "fun = @(x) ...". Would anyone be willing to tell me how to correct it?
1 Comment
Torsten
on 22 Jul 2023
Please enclose the code where you tried to use "fmincon".
Accepted Answer
More Answers (0)
Categories
Find more on Surrogate Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!