Hi,
one way to solve this is fsolve: 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:
You can use also use fmincon, by using a little trick: format long
x0 = [1 1 1 1 1];
lb = [0 0 -inf -inf -inf];
ub = [inf inf inf inf inf];
result = fmincon(@eqn1,x0,[],[],[],[],lb,ub,@nonlcon);
format short
function obj_fun = eqn1(x)
x11 = x(1);
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