Minimising non linear function

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);

 Accepted Answer

John D'Errico
John D'Errico on 1 Jun 2016
So what is your question? You have stated what you want. Did this not work?
Ok, so I do wonder why you are trying to use the wrong tool for the problem. After all, quadprog does not handle general nonlinear programming problems, subject to general nonlinear inequality constraints. So your problem, whatever it might be might be as simple as reading the help for the tool and realizing that your call is meaningless in that context.
There are other things. For example, you define a set of lower bounds, but then never pass them in. MATLAB cannot read your mind.
My guess is you need to use fmincon. (Properly! Read the help.) But the crystal ball is so foggy. I just cannot read your mind either.

6 Comments

ok sir, forget about code, it was my mistake as I working on this code, I uploaded one of my trail code. Now, my question is can I declare function as I did in my code first part, if so how can I minimise this function with four inequality linear constraints.
Yes you can declare your functions the way you show.
To use four inequality linear constraints see the fmincon documentation about the A and b parameters
Thank you for the help, Here my doubt is, how can I get global minimum of this equation with inequality linear constraints.
It is uncommon to be able to find the global minimum of nonlinear functions and be sure you have found it. fmincon is not a global minimizer. You can try the tools from the Global Optimization Toolbox, such as ga or simulannealbnd or patternsearch or create a MultiStart problem; these will increase your chance of finding a minima that turns out to be global, but you cannot be certain.
What are the ways I have to get a global minimum of my function, It should be certain.
You cannot ever insure that a solution is a global minimizer, unless you can provide sufficient information about the derivatives of the function. That is, one can always provide some function that is everywhere 1, except at some single point, it takes on the value zero. Finding the location of that minimizer will be impossible to do if we only are allowed to sample the function. Unless the optimizer is incredibly lucky, then it will NEVER find the min.
And of course, we can always provide a function that is arbitrarily close to the counter-example I gave above.
This is a problem with global solvers. Unless you can insure the function is sufficiently well-behaved, then no solver can positively always succeed.
Having said that, there are global minimization tools. In fact, MATLAB has a global minimization toolbox, that will try to solve for a global min. TRY is the operative word here. Such global methods will be more robust than a normal solver, at some cost in time for the solve.

Sign in to comment.

More Answers (2)

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.
can I use any other software on my problem, please suggest

4 Comments

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.
can I use rand to choose my variables from a region and then applying if condition to satisfy my objective function condition equals to zero. here I am attaching my trail for one variable.
vexp=4854;
x(1)=randi([0 1e5],1,1);
f=((x(1)^2-vexp^2)/vexp^2)^2
if f==0
x=x(1);
end
but it results random numbers with out satisfying the if condition. please help me
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.
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.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!