Solving an optimization problem with several functions
1 回表示 (過去 30 日間)
古いコメントを表示
I have the following 4 equations:
eq1=x11 - (9*2^(1/2)*u2)/(20*((2^(1/2)*u2)/2 - (5^(1/2)*v2)/5)) + (3*5^(1/2)*v2)/(50*((2^(1/2)*u2)/2 - (5^(1/2)*v2)/5))
eq2=x21 + (3*u2*v2)/(5*((2^(1/2)*u2)/2 - (5^(1/2)*v2)/5))
eq3=1/5 - (3*2^(1/2)*5^(1/2))/(50*((2^(1/2)*u2)/2 - (5^(1/2)*v2)/5))
eq4=x22 - (3*2^(1/2)*u2)/(20*((2^(1/2)*u2)/2 - (5^(1/2)*v2)/5)) + (9*5^(1/2)*v2)/(50*((2^(1/2)*u2)/2 - (5^(1/2)*v2)/5))
for which I want to find the parameters
x11,x21,x22,u2,v2
for which all the equations are 0 (or close to zero), subject to the constraints, and
So, I'm not sure how to approach this. I found the and the function, but they only accept a single function handle and I'm not sure if they are suited to solve this problem.
Is there a function in Matlab to solve such problems?
Any help appreciated!
0 件のコメント
採用された回答
Stephan
2018 年 12 月 16 日
編集済み: Stephan
2018 年 12 月 17 日
Hi,
format long
x0 = [1 1 1 1 1];
options = optimoptions('fsolve', 'Algorithm', 'Levenberg-Marquardt');
result = fsolve(@equations, x0, options)
format short
function F = equations(x)
x11 = x(1);
x21 = x(2);
x22 = x(3);
u2 = x(4);
v2 = x(5);
F(1) = x11 - (9*2^(1/2).*u2)/(20*((2^(1/2).*u2)/2 - (5^(1/2).*v2)/5)) +...
(3*5^(1/2).*v2)/(50*((2^(1/2).*u2)/2 - (5^(1/2).*v2)/5));
F(2) = x21 + (3.*u2.*v2)/(5*((2^(1/2).*u2)/2 - (5^(1/2).*v2)/5));
F(3) = 1/5 - (3*2^(1/2)*5^(1/2))/(50*((2^(1/2).*u2)/2 - (5^(1/2).*v2)/5));
F(4) = x22 - (3*2^(1/2).*u2)/(20*((2^(1/2).*u2)/2 - (5^(1/2).*v2)/5)) +...
(9*5^(1/2).*v2)/(50*((2^(1/2).*u2)/2 - (5^(1/2).*v2)/5));
end
with result:
result =
0.768206088209485 0.308533559026783 0.431793911790578 1.046940639379436 -0.465961843087484
Be careful! fsolve doesnt handle constraints. In this case all solutions except v2 are >0, so that your constraints are met.
EDIT:
format long
x0 = [1 1 1 1 1];
lb = [0 0 -inf -inf -inf];
ub = [inf inf inf inf inf];
% options = optimoptions('fmincon', 'Algorithm', 'Levenberg-Marquardt');
result = fmincon(@eqn1,x0,[],[],[],[],lb,ub,@nonlcon);
format short
function obj_fun = eqn1(x)
x11 = x(1);
% x21 = x(2);
% x22 = x(3);
u2 = x(4);
v2 = x(5);
obj_fun = x11 - (9*2^(1/2).*u2)/(20*((2^(1/2).*u2)/2 - (5^(1/2).*v2)/5)) +...
(3*5^(1/2).*v2)/(50*((2^(1/2).*u2)/2 - (5^(1/2).*v2)/5));
end
function [c,ceq] = nonlcon(x)
x11 = x(1);
x21 = x(2);
x22 = x(3);
u2 = x(4);
v2 = x(5);
c = [];
ceq(1) = x11 - (9*2^(1/2).*u2)/(20*((2^(1/2).*u2)/2 - (5^(1/2).*v2)/5)) +...
(3*5^(1/2).*v2)/(50*((2^(1/2).*u2)/2 - (5^(1/2).*v2)/5));
ceq(2) = x21 + (3.*u2.*v2)/(5*((2^(1/2).*u2)/2 - (5^(1/2).*v2)/5));
ceq(3) = 1/5 - (3*2^(1/2)*5^(1/2))/(50*((2^(1/2).*u2)/2 - (5^(1/2).*v2)/5));
ceq(4) = x22 - (3*2^(1/2).*u2)/(20*((2^(1/2).*u2)/2 - (5^(1/2).*v2)/5)) +...
(9*5^(1/2).*v2)/(50*((2^(1/2).*u2)/2 - (5^(1/2).*v2)/5));
end
What happens here?
The first function takes your first equation as objective function to minimize. The second function defines the nonlinear constraints - here that all equations should be equal to zero. Since we use fmincon we can define lower and upper bounds to ensure that {x11, x22} > 0.
The result is:
result =
0.733946078616734 0.360292286378543 0.466053921384332 0.970332937199620 -0.587089255763525
which meets the constraints. To check the results you could call the nonlcon-function with the results. Add this line after the fmincon call:
[~, check_result] = nonlcon(result)
This should end near by zero.
check_result =
1.0e-07 *
-0.036086063998075 0.515513386978306 -0.002526874820497 0.036096726441226
This seems to be a good result.
Best regards
Stephan
3 件のコメント
Stephan
2018 年 12 月 17 日
See my edited answer. If it was useful for you, you can accept and/or like helpful answers. This is the easiest way to thak the volunteers here for their work.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Surrogate Optimization についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!