Non-linear equation optimization

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
Walter Roberson on 24 Mar 2021
Edited: Walter Roberson on 24 Mar 2021
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

Thanks very much Walter for your quick answer. The original equation f(x) reflects an experimental result. The value of kr=0 would be not reasonable experimentally. What is your suggestions to find the optimum values of kr and kad from the original equation. I really appreciate your suggestions.
Matt J
Matt J on 24 Mar 2021
Edited: Matt J on 24 Mar 2021
Walter has already told you what the optimizing values are. The solution to the problem you have presented will not change just because you expect a different result.
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
f = 
sol1 = solve(f + delta_f == 0, kad, 'returnconditions', true)
sol1 = struct with fields:
kad: [1×1 sym] parameters: [1×0 sym] conditions: [1×1 sym]
sol1.kad
ans = 
sol1.conditions
ans = 
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))
fnew = 
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)
best_kad = 
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)
kad0 = 
vpa(kad0)
ans = 
f0 = subs(f, [kr, kad], [guess_kr, kad0])
f0 = 
0
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)
ans = 1×2
498 1
[~, 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
better_f = 
0
idx =
1
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
Hello all, Sorry for the late response due to working with other lab stuff. I really appreciate all the efforts in helping me with this equation.
I want to clarify the following:
- The value of 0.01085 is an experimental result that reflects both kr and kad lumped together.
- The value of 60 is the concentration of the material that was used for the experiment.
- The equation formula is as I posted: (kr*kad)/(1+60*kad)-0.01085
- For your questions about the values, any positive value for both variables would be acceptable except zero. From the mathematical perspective, negative values are not acceptable as well. I am saying this because the lumped parameter of both variables is a real number found in the lab. It could be one of them has a value of 1 and the other one 0.01085.
Again, I really appreciate the time and efforts that made for the question.
Sincerely
Waleed
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
Thanks very much Walter for your quick response. So, kr>= (13020/20000=0.651). Based on your experience, how can I find the optimum value for kr and kd of this equation?
Thank you,
Waleed
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
I understand that. Thanks very much for all your kind help with this question.
Waleed
This is fair enough. I can not thank you enough for all your clarification and your kind help with this equation.
Sincerely,
Waleed

Sign in to comment.

Categories

Asked:

on 24 Mar 2021

Commented:

on 24 Mar 2021

Community Treasure Hunt

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

Start Hunting!