Non-linear equation optimization
Show older comments
I got minimum local point and want the global minimum. GlobalSearch function did not work
x0=[0.5 0.5];
%Define function to calculate the nonlinear value
xopt=fmincon(@objective,x0,[],[],[],[],[],[],@constraint,[]);
%optimized value
W1opt=f(xopt);
function value = f(x)
kr=x(1);
kad=x(2);
value=(kr*kad)/(1+60*kad)- 0.01085;
end
%Define objective function for optimization
function obj= objective(x)
obj= -f(x);
end
%Define constraint for optimization
function [c,ceq]= constraint(x)
c= f(x)-0;
ceq=[];
end
%call solver to minimize the objective function given the constraint
Answers (1)
Walter Roberson
on 24 Mar 2021
Edited: Walter Roberson
on 24 Mar 2021
1 vote
The following analysis is incorrect; I posted better below
=== incorrect analysis follows ===
The global solution to that is x(1)==0 and kad any finite value other than -1/60
Your nonlinear inequality is f(x)-0 which is the same as f(x)<=0. f(x) is the original function. But you ask to minimize objective which is -f(x) so you want -f(x) to be as small as possible while satisfying f(x)<=0. The optimal combination for that is f(x)==0. Which is achieved when kr==0 provided the denominator is not 0.
Could the denominator be infinite instead? No, because the numerator has the same power of the second variable so the ratio never tends to 0.
10 Comments
Waleed Jadaa
on 24 Mar 2021
Walter Roberson
on 24 Mar 2021
Is it only zero exactly that is not valid for kr ? Are complex values possible? Are negative values possible? If you have ranges, then express them through lb and ub parameters to fmincon()
If f(x) <= 0 as required by constraints then it follows that there is a non-negative value
such that
. That gives us an equality boundary condition.
Let us find the value of kad that achieves the boundary conditions, in terms of kr and
:
format long g
syms kr kad delta_f
assume(delta_f >= 0)
f = (kr*kad)/(1+60*kad)- 0.01085
sol1 = solve(f + delta_f == 0, kad, 'returnconditions', true)
sol1.kad
sol1.conditions
Now we need to minimize -f (this is given as the objective), which is the same as maximizing f. We can possibly take calculus approaches with derivatives. Let us substitute the determined kad into the objective:
fnew = simplify(subs(f, kad, sol1.kad))
This makes sense: kad was the value that made
so
and that is what is to be optimized.
To maximize a negative we would hope that the quantity can be negative, and then we ask what the most negative it can be is. But delta_f is defined as positive: it is the amount by which f(x) is less than 0, and if we want to maximize f(x) then it makes sense that
(amount below 0) should be as small as possible -- in particular, best would be if
is equal to its lowest bound, 0 exactly. So
best_kad = subs(sol1.kad, delta_f, 0)
You can now substitute kr in whatever bounds you have. For example, if kr must be positive,
guess_kr = 1e-100;
kad0 = subs(best_kad, kr, guess_kr)
vpa(kad0)
f0 = subs(f, [kr, kad], [guess_kr, kad0])
Let's try some other values:
trial_kr = randn(1000,1)*10;
trial_kad = randn(1000,1)*10;
trial_f = vpa(subs(f,{kr,kad},{trial_kr,trial_kad}));
mask = trial_f-0 <= 0; %nonlinear constraint
selected_kr = trial_kr(mask);
selected_kad = trial_kad(mask);
selected_f = trial_f(mask);
size(selected_kr)
[~, maxidx] = min(-selected_f); %objective is minimizing -f
best_kr = selected_kr(maxidx);
best_kad = selected_kad(maxidx);
best_f = selected_f(maxidx);
disp([best_kr, best_kad, best_f])
[better_f, idx] = min(-[f0, best_f]) %let us compare to what we found at the boundary
Here idx 1 means that f0 (the solution we found analytically) is better (min of -f is less positive) than the solution we found through random coefficients
Waleed Jadaa
on 24 Mar 2021
Walter Roberson
on 24 Mar 2021
If kad must be non-negative then 217/(20000*kr - 13020) must be positive, so kr must be greater than 13020/20000 . But you don't want right at the boundary as that gives infinite kad. The larger the kr value, the smaller the kad. They two are equal at 467201^(1/2)/2000 + 651/2000 approximately 0.66726
Waleed Jadaa
on 24 Mar 2021
Walter Roberson
on 24 Mar 2021
Edited: Walter Roberson
on 24 Mar 2021
Your current constraints work out to
kr > 13020/20000
kad = 217 / (20000*kr - 13020)
and you cannot resolve further than that unless you have some other constraint or some measure of which values are "better". This relationship between values gives f(x) = 0 which satisfies the nonlinear constraint f(x) - 0 <= 0, and optimizes -f(x) being as furthest from +infinity as possible (that is, f(x) being maximized.)
The larger the kr value, the smaller the kad value. You can make kad as small and positive as you want, at the expensive of large kr. You can make kr as little greater than 13020/20000 as you want, at the expense of making kad nearly infinite. Which to use would be a decision based upon constraints that you have not stated. About the only "natural" point would be to judge that since you do not have any good reason to make one large and the other small, make them equal, which happens at 467201^(1/2)/2000 + 651/2000
Waleed Jadaa
on 24 Mar 2021
Waleed Jadaa
on 24 Mar 2021
Categories
Find more on Systems of Nonlinear Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!