find the absolute maximum of a symbolic multi-variable function

24 Ansichten (letzte 30 Tage)
behrad ghazinouri
behrad ghazinouri am 28 Mai 2022
Beantwortet: Nipun am 31 Okt. 2023
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 Kommentare
behrad ghazinouri
behrad ghazinouri am 3 Jun. 2022
@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
Walter Roberson
Walter Roberson am 3 Jun. 2022
See also https://www.mathworks.com/matlabcentral/answers/1730430-find-min-max-of-variable-values-that-satisfy-certain-constraints#comment_2195225

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Nipun
Nipun am 31 Okt. 2023
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

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by