Minimising non linear function
Mostrar comentarios más antiguos
I have a non linear function with 3 variables and 4 linear constraint inequalities. I want get values of three variables with minimizing non linear function using Least square method.
creating function file
function f=objfun(x)
%%%longitudinal velocities %%%
rho=8.96e-3;
voigtl=sqrt((((x(1)+2*x(2))/3)+((4/15)*(x(1)-x(2)+3*x(3))))/rho);
reussl=sqrt((((x(1)+2*x(2))/3)+((4/3)*(5*x(3)*(x(1)-x(2))/(3*(x(1)-x(2))+4*x(3)))))/rho);
velham=(voigtl+reussl)/2;%%longitudinal velocity as per Hill criterion in arithmetic mean
velhgm=sqrt(voigtl*reussl);%%longitudinal velocity as per Hill criterion in geometric mean
velexp=4854; %%experimentally measured velocity
f=((velham)^2-(velexp)^2)/(velexp)^2;
end
creating contraints
function [c, ceq] = confun(x) % Nonlinear inequality constraints
c = [-x(1)-2*x(2); -x(3);-x(1)+x(2);((x(1)-x(2))/2)-x(3)]; % Nonlinear equality constraints
% Nonlinear equality constraints
ceq = [];
end
minimizing function used
x0 = [1,1,1]; % Make a starting guess at the solution
options = optimset('TolFun',1e-10,'MaxIter',4000);
% A=[-1,-2,0; 0,0,-1; -1,1,0; 1/2,-1/2,-1;];
% b=[0,0,0,0];
lb=[50,50,50];
ub=[];
[x,fval,iterations] = quadprog(@objfun,x0,[],[],[],[],[],[],@confun,options);
Respuesta aceptada
Más respuestas (2)
Walter Roberson
el 2 de Jun. de 2016
There are no known general ways to be certain that you have reached the global minimum of a nonlinear function.
Sometimes you are able to solve for the zeros of the derivative and then substitute into the second derivative to determine whether you have reached a maxima or minima. In the case where the roots can be mechanically completely found, you can then run through all of the combinations, evaluating the function on each combination, and pick out the global minimum. But you need to be careful: if the global minimum is not a point that fits your constraints, then you also have to check all along your constraint boundaries.
I ran some calculations on your objective function. If you ignore your constraints, then the global minimum occurs when x3 = (x1 - x2)/2, at which the function value will be x1/(velexp^2*rho) - 1 which in turn would be minimized at x1 = -infinity .
What you have coded as nonlinear inequality constraints are really a mix of bounds constraints and linear inequality constraints. You should rewrite them that way. For example the first element
-x(1)-2*x(2)
can be written with A = [-1 -2 0], b = [0] . The algorithms are much more efficient at dealing with linear constraints or bounds constraints than they are with nonlinear constraints.
karthik karuparthi
el 2 de Jun. de 2016
0 votos
4 comentarios
Walter Roberson
el 2 de Jun. de 2016
ga(); fmincon(); simulannealbnd(); swarm(); MultiStart() with run(); patternsearch(). Possibly there are some routines written by other people that might help, such as ACO (Ant Colony Optimization) or ABC (Artificial Bee Colony). Perhaps one of the tomcat routines.
However, aside from using calculus, there are no general algorithms that can promise to find the global minimum.
On the other hand, you can show that your function has a minima that is negative and arbitrarily close to -1 (above it), under the condition that x1 = 0, x2 = 0, and x3 is positive and arbitrarily small. At the moment it does not appear that you can reach -1 itself; values below -1 cannot happen without complex numbers.
karthik karuparthi
el 3 de Jun. de 2016
Editada: karthik karuparthi
el 3 de Jun. de 2016
Walter Roberson
el 3 de Jun. de 2016
Ummm, you could, but it is pointless to do so. You can see by examination that for f to be 0 that that part inside the ()^2 must be 0, so ((x(1)^2-vexp^2)/vexp^2) must be 0. The denominator is not infinite so that is satisfied only when (x(1)^2-vexp^2) is 0, which is equivalent to requiring that x(1)^2 = vexp^2, which can only be the case if x(1) is exactly equal to +/- vexp . You could put your code in a loop and since you generate only positive random numbers, your loop would keep iterating until eventually it happened to generate 4854 exactly.
Notice that you switched here to a polynomial in one variable. Those are easy to deal with. Your original problem is in 3 variables, not one variable.
Walter Roberson
el 4 de Jun. de 2016
Above I said that you can show that the function has a minima that is arbitrarily close to -1. That turned out to be incorrect, based upon the assumption that only real values were to be produced from the sub-expressions. If you allow the sub-expressions to become complex valued, then because of the (velham)^2, the complex values can potentially be turned into negative values. The actual limit is the one I noted earlier, where x1 = x2 and x3 approaches -infinity, which gets you a minima of -infinity.
However, you had lb = [50, 50, 50] in your original post. If those are indeed the lower bounds to use, then the minima for function is at [50, 75, 50], not at the lower bound. The location is
x2 = (1/4)*x1 - x3 + (1/4)*sqrt(9*x1^2+56*x1*x3+16*x3^2)
and the minimum function value is
-1 + ((7/40) * x1 + (1/10)*x3 + (1/40)*sqrt(9*x1^2+56*x1*x3+16*x3^2)) / (velexp^2*rho)
which at x1 = 50, x3 = 50 gives you x2 = 75 and -1 + 25/(rho*velexp^2) as the minimum, whereas if you just took the boundary x1 = 50, x2 = 50, x3 = 50 you would get
-1 + (15*sqrt(5)+35) / (velexp^2*rho)
If you allow some of the x1, x2, x3 to go a bit negative (e.g, around -165) then you can reduce the minima to a little below -1; and as I noted earlier if you allow the x1, x2, x3 to go fairly negative (e.g., < about -1250000) then you can go down to -infinity.
Categorías
Más información sobre Solver Outputs and Iterative Display en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!