# What optimizer should I use?

2 views (last 30 days)
MENGZE WU on 12 May 2022
Commented: Walter Roberson on 12 May 2022
I have a function f(T, R1, R2), where R1 and R2 are in the range of (0,20], and I want get R1 and R2 value to make f() as samll as possible. However, the T is also a variable I can't control and it can vary from 200 to 400. I want f() to be as small as possible even when the T is changing. Could someone please help me to find an optimizer can I use?
This is the f() I want to optimized:(all constants except for R1 R2 and T) k = 1.381e-23
q = 1.6e-19
phiB = 0.6
m = 1.5
gamma = 0.2
##### 2 CommentsShowHide 1 older comment
MENGZE WU on 12 May 2022
All contants are positive.

Chunru on 12 May 2022
Consider your objective function f(T, R1, R2), whose dependence on R2 lies on the first term only. To minimise f, R2 need to be as small as possible. For the range R2 in (0,20], R2-->0.
Now consider R1. When R1 increases, the numerator of the second term (rkmlog(R1)) increases. The denominator decreases (assume T, k, m, q >=0). So the second term (with - ) decrease. So the larger R_1, the smaller f. To mininize f, you choose largest R2.
We have assumed T, k, m, q >=0. For other combination the results may be different. Also note that the term inside sqrt may be negative and the problem is not well defined in this case.

John D'Errico on 12 May 2022
This is not a problem of finding an optimizer. This is a problem of understanding how to formulate a problem so that it is possible to solve at all.
What does it mean to minimize f? It is not going to be possible to find simple values of R1 nd R2 that minimize the function for ALL values of T. And since you don't even tell us what all of the other variables are thus k, m, q, phiB, it is not easy to give better advice.
Anyway, you need to convert this to a problem with a SCALAR result. An optimizer cannot apply to a function over an entire region. But the integral of the square of f(T) will be a scalar function of the two parameters R1 and R2. When that integral is small, then the function could be deemed to be as small possible. Now you can use any optimization tool.
A common mathematical term for that integral is a functional, a function applied to the family of functions f(T). This is like assuming T has an unknown random value, that is uniformly distributed on the interval [200,400]. In the case where you have better information about the distribution of T than uniform, then you should use it, computing instead the integral of f(T)^2*P(T), where P(T) is the PDF of the variable T. That would now give you a weighted functional, assigning more importance to those places where T is more likely to lie.
Walter Roberson on 12 May 2022
Depending on the values of the constants, it might be the case that min R2, max R1 is optimal. With different constants there is a smaller R1 that is optimal because division by 0.

Walter Roberson on 12 May 2022
By examination, assuming that the constants are positive:
• the first term is smallest when log(R2) is smallest, which will occur at the smallest R2 value that you permit. If 0 were permitted then log(0) would be -infinity which would give you a minimum for any finite value of the second term.
• the second term numerator would be negative if log(R1) is negative. assuming that the constants are positive, the subtraction of a negative log would give a positive value so the denominator would be positive. Negative divided by positive would be negative. But you are subtracting that term so you would be increasing the function value. From this we deduce that R1<1 leads away from the minimum.
• So examine R1>1 so log() is positive. If the sqrt() is finite positive then you would have positive numerator and denominator leading to a positive value, which is being subtracted, improving the minimum. This is promising. And the larger the amount subtracted the better the minimum. Thus as long as the denominator remains finite positive, for any given T value, the minimum is at the maximum permitted R1 value.
• If what is inside the sqrt() goes negative then you get a complex value, and complex values are not considered minimum.
• The remaining possibility is that what is inside the sqrt() is 0. This case leads to a positive numerator divided by 0, which gives +infinity to be subtracted from the leading term, giving you a -infinity minimum.
You can solve for the R1 value that leads to the negative infinity minimum in terms of T. Beyond that R1 you go complex.
In cases where the R1 that would lead to that situation is larger than the R1 limit, then the function minimum is at the largest permitted R1.
The overall solution is then:
• minimum permitted R2
• maximum permitted R1 in some cases
• critical maximum R1 in terms of T in some cases (and in those cases in theory R2 does not matter.)

R2022a

### Community Treasure Hunt

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

Start Hunting!