This would fit well under the non linear constrained optimization category, fmincon is helpful here. Fmincon allows you to solve the non linear system while placing upper and lower bounds on the solution vector. The problem is that the solution will depend on your starting point... So if you have a good guess for where the solution should be that helps GREATLY.
The analogy is like asking the solver to climb to the top of the mountain in front of it, or asking it to find the tallest peak in Europe by backpacking from some random starting point. When you are close you can just walk 'up'.
Anyway, here's how you can do this.
function test()
a = .05
b = 88
xo = [100 100 100 100 a b]
options = optimset('MaxFunEvals',1E5, ...
'MaxIter', 1E5, ...
'TolFun', 1E-32, ...
'TolX', 1E-32, ...
'TolCon', 1E-32);
x = fmincon(@(X) Ftest(X), xo, [], [], [], [], ...
[-inf -inf -inf -inf a b], [], [], options)
Final_Project_2(x)
function F = Ftest(x)
F = norm(Final_Project_2(x))
end
function F = Final_Project_2(x)
F = [(1/x(1)) + (1/x(2))- (2/(7*x(3)));
(x(3)+2*x(4))*(15*x(2))/((x(1)+x(2))*x(3)-0.7/x(3))-14;
(x(3)*((0.576*x(2)/(x(1)+x(2))*x(3)) - 0.27/x(3)))/(x(3)+(0.576*x(2)/(x(1)+x(2))*x(3)) - 0.27/x(3)) - x(5);
((0.576*x(2)*x(3)/(x(1)+x(2))*x(3)) - 0.27*x(4)/x(3))-x(6)];
end
end
x =
258.0438 84.3372 24.9576 34.8035 3.0926 88.0000
ans =
0.0043 -0.0000
0.0001 -0.0000
Note how the solver slammed against the lower bound on b. You can try playing with the initial guess and see if you can get it to find a nicer min. No solution is guaranteed...
This is the fun part, you can do better. Your system is not just a cost function but a constraint on x. Similar code, but using that information and you have a strong solution.
function test()
a = .05
b = 88
xo = [100 100 100 100 a b]
options = optimset('MaxFunEvals',1E4, ...
'MaxIter', 1E4, ...
'TolFun', 1E-32, ...
'TolX', 1E-32, ...
'TolCon', 1E-32);
x = fmincon(@(X) Ftest(X), xo, [], [], [], [], ...
[-inf -inf -inf -inf a b], [], @(X) xcon(X), options)
Final_Project_2(x)
function F = Ftest(x)
F = norm(Final_Project_2(x))
end
function [c,ceq] = xcon(x)
c = []
ceq = [(1/x(1)) + (1/x(2))- (2/(7*x(3)));
(x(3)+2*x(4))*(15*x(2))/((x(1)+x(2))*x(3)-0.7/x(3))-14;
(x(3)*((0.576*x(2)/(x(1)+x(2))*x(3)) - 0.27/x(3)))/(x(3)+(0.576*x(2)/(x(1)+x(2))*x(3)) - 0.27/x(3)) - x(5);
((0.576*x(2)*x(3)/(x(1)+x(2))*x(3)) - 0.27*x(4)/x(3))-x(6);
(x(3)*((0.576*x(2)/(x(1)+x(2))*x(3)) - 0.27/x(3)))/(x(3)+(0.576*x(2)/(x(1)+x(2))*x(3)) - 0.27/x(3)) - x(5);
((0.576*x(2)*x(3)/(x(1)+x(2))*x(3)) - 0.27*x(4)/x(3))-x(6)];
end
function F = Final_Project_2(x)
F = [(1/x(1)) + (1/x(2))- (2/(7*x(3)));
(x(3)+2*x(4))*(15*x(2))/((x(1)+x(2))*x(3)-0.7/x(3))-14;
(x(3)*((0.576*x(2)/(x(1)+x(2))*x(3)) - 0.27/x(3)))/(x(3)+(0.576*x(2)/(x(1)+x(2))*x(3)) - 0.27/x(3)) - x(5);
((0.576*x(2)*x(3)/(x(1)+x(2))*x(3)) - 0.27*x(4)/x(3))-x(6)];
end
end
x =
360.8859 132.2940 27.6590 34.2885 3.6943 117.8688
ans =
1.0e-14 *
-0.0002
0.1776 -0.0444
0
Think of the second method as giving the backpacker a set of trails/roads to use. It guides the solver through the R^6 space.