find the absolute maximum of a symbolic multi-variable function

Hi,
I have a function with multiple variables and I want to find the global maximum of the function.
Here are the variables and the function:
syms I1 I2 T1 T2 theta1 x
f1=(((I2*((T1 + T2 + T2*x)/theta1 + (T1 + T2 + T2*x)/(theta1*x)))/2 + (I1*(T1 + T2 + T2*x))/(2*theta1*x))/(I1*I2) - ((I2*((T1 + T2 + T2*x)/theta1 + (T1 + T2 + T2*x)/(theta1*x)) + (I1*(T1 + T2 + T2*x))/(theta1*x))^2/(I1^2*I2^2) - (4*(T1 + T2 + T2*x)^2)/(I1*I2*theta1^2*x))^(1/2)/2)^(1/2)/(2*pi)
I need to find the global maximum of f1 as a function of x.
Now the I1 I2 T1 T2 and theta1 are parameters independent from x.
and if we calculate the derivitive of the function and solve it for x to find the local max/min, the theta1 will be cancelled. Here is the code:
f1diff=diff(f1,x)==0;
f1DiffIso=isolate(f1diff,x);
f1Optimized=subs(f1, x, rhs(f1DiffIso));
The result will be MASSIVE:
f1Optimized =(((I2*((T1 + T2 + (I1*T2^2 + I1*T2*(T2*(T1 + T2))^(1/2) - I2*T1*(T2*(T1 + T2))^(1/2) + I1*T1*T2)/(I2*T1))/theta1 + (I2*T1*T2*(T1 + T2 + (I1*T2^2 + I1*T2*(T2*(T1 + T2))^(1/2) - I2*T1*(T2*(T1 + T2))^(1/2) + I1*T1*T2)/(I2*T1)))/(theta1*(I1*T2^2 + I1*T2*(T2*(T1 + T2))^(1/2) - I2*T1*(T2*(T1 + T2))^(1/2) + I1*T1*T2))))/2 + (I1*I2*T1*T2*(T1 + T2 + (I1*T2^2 + I1*T2*(T2*(T1 + T2))^(1/2) - I2*T1*(T2*(T1 + T2))^(1/2) + I1*T1*T2)/(I2*T1)))/(2*theta1*(I1*T2^2 + I1*T2*(T2*(T1 + T2))^(1/2) - I2*T1*(T2*(T1 + T2))^(1/2) + I1*T1*T2)))/(I1*I2) - ((I2*((T1 + T2 + (I1*T2^2 + I1*T2*(T2*(T1 + T2))^(1/2) - I2*T1*(T2*(T1 + T2))^(1/2) + I1*T1*T2)/(I2*T1))/theta1 + (I2*T1*T2*(T1 + T2 + (I1*T2^2 + I1*T2*(T2*(T1 + T2))^(1/2) - I2*T1*(T2*(T1 + T2))^(1/2) + I1*T1*T2)/(I2*T1)))/(theta1*(I1*T2^2 + I1*T2*(T2*(T1 + T2))^(1/2) - I2*T1*(T2*(T1 + T2))^(1/2) + I1*T1*T2))) + (I1*I2*T1*T2*(T1 + T2 + (I1*T2^2 + I1*T2*(T2*(T1 + T2))^(1/2) - I2*T1*(T2*(T1 + T2))^(1/2) + I1*T1*T2)/(I2*T1)))/(theta1*(I1*T2^2 + I1*T2*(T2*(T1 + T2))^(1/2) - I2*T1*(T2*(T1 + T2))^(1/2) + I1*T1*T2)))^2/(I1^2*I2^2) - (4*T1*T2*(T1 + T2 + (I1*T2^2 + I1*T2*(T2*(T1 + T2))^(1/2) - I2*T1*(T2*(T1 + T2))^(1/2) + I1*T1*T2)/(I2*T1))^2)/(I1*theta1^2*(I1*T2^2 + I1*T2*(T2*(T1 + T2))^(1/2) - I2*T1*(T2*(T1 + T2))^(1/2) + I1*T1*T2)))^(1/2)/2)^(1/2)/(2*pi)
Now what I want know is that if this is a local max or min.(Iknow that it's probabely a max but I don't know how to code the proof for it) and consequently I want to see if its the absolute max/min or not.
I assume there is no definite answer for this and there should be some conditions such as a certain range for T1, T2, I1 & I2. But I don't know how to find that. Any help will be appreciated.

9 Comments

Are any of the variables constrained? For example, T and I variables all real-valued? Is x real valued?
What is the limit as T2 approaches 0?
Here are the constrains:
All of the variables are real-valued.
0=<T1,T2<0.01 & 0=<T2/T1<10
0<I1,I2<0.001 & 0<I2/I1<10
0<theta1<10
based on the numerical trials when T2 approaches 0 there will be no local maximom and the function is descending. But in general I have no limit for that.
@Walter Roberson I appreciate if you let me know what you had in mind when you asked me the question. I still could'nt figure this out.
Since the x appears in the denominator, my guess is that the maximum is +Inf.
Take x=0 and see what happens.
The f1Optimized that you calculate has division by T2 and by T1*T2 or T1+T2. Non-zero constraints for those would have ruled out some edge cases.
My tests show that the limit as T2 goes to 0 is 0, but that the limit as T1 goes to 0 is not defined.
f1Optimized also involves sqrt() of an expression. Depending on the constraints, the value in the sqrt() is not necessarily non-negative. I looked a bit at that, and in the time I spent I could not rule out the possibility, and realized that it called for numeric simulation. Which I have not started.
@Torsten I see what you're saying. when I insert x=0 it gives zero division error. However, I tried very small values for x and the result is not ascending. Infact the result in the local maximom remains much bigger that the result for x->0 so my guess is that x=0 is not the answer.
@Walter Roberson Thank you for the effort!
I've used multiple for loops to have some numerical results and while T2>0 the result is always similar to the red diagram in the attached plot.
So let me ask my question in another way.
lets say I1 I2 T1 T2 theta1 are constant parameters and only the x is a variable.
Is there any way to define conditions for these constant parameters and find the global min/max of the function parameterically?
P.s. I'm almost sure that the value that I'm looking for, is actually the value of the local exterma, which is
x == (I1*T2^2 + I1*T2*(T2*(T1 + T2))^(1/2) - I2*T1*(T2*(T1 + T2))^(1/2) + I1*T1*T2)/(I2*T1*T2)
I just need to prove it.
@Matt J Hi, I've seen you comment on a question very similar to my question here, were you used fminsearch to find parameters. I tried to replicate your work there but I was not successful.
I really appreciate it if you could take a look at my question above and let me know what you think.
I'm refering to this conversation:
https://www.mathworks.com/matlabcentral/answers/81268-how-to-i-find-a-range-of-parameters-that-admit-positive-solutions
See also https://www.mathworks.com/matlabcentral/answers/1730430-find-min-max-of-variable-values-that-satisfy-certain-constraints#comment_2195225

Sign in to comment.

Answers (1)

Hi Behrad,
I understand that you are trying to find the local extrema of the given symbolic equation dependent on x. I assume that the symbolic variables are independent of x. MATLAB's symbolic math toolbox can be leveraged to get information about the extremas.
By default, symbolic expressions can be complex (imaginary and real). If the function parameters are restricted to be real, the following command can be used:
assume(x, 'real')
Since the other variables are independent of x, they shall be bounded. Use the following command for each variable to get a bounded value:
[limit(f, x, sym(inf)), limit(f, x, -sym(inf))]
Now, in order to check for the nature of extremas, I recommend calculating the second order derivative of the equation and subsituting the value of rhs(f1DiffIso) in the expression f1 to check if the value is negative (local maxima) or positive (local minima)
f1Diff2 = diff(f1,x,2);
y = subs(f1Diff2, x, rhs(f1DiffIso))
You can use the following command to evaluate the value:
ans = vpa(y,6) % approximates the answer up to 6 decimal places
Additionally, you may also check the nature of extrema by supplying values x-1 or x+1 to the expression. However, all these steps require limits on the parameters independent of x.
Link to resources:
  1. Symbolic Math Toolbox: https://in.mathworks.com/products/symbolic.html
  2. Maxima, Minima in MATLAB: https://in.mathworks.com/help/symbolic/maxima-minima-and-inflection-points.html
Hope this helps.
Regards,
Nipun

Products

Release

R2021a

Asked:

on 28 May 2022

Answered:

on 31 Oct 2023

Community Treasure Hunt

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

Start Hunting!