Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
fminsearch not finding a basic minimum

Subject: fminsearch not finding a basic minimum

From: Shannon

Date: 3 Feb, 2011 23:20:04

Message: 1 of 8

This is my first shot at applying one of the built-in minimization functions within MATLAB, and i'm getting a puzzling result that the command seems to be unable to find the minimum of a simple function.

To start with, I have two functions:
JC_stress1=(A+B*strain^n)*(1+C*ln(edot_star))*(1-(deltaT/(Tm-T0))^m);
JC_stress2=(deltaT*rho*cp)/(xeta*strain);
where A, B, C, n, m, Tm, T0, rho, cp, xeta, edot_star and strain are all constants

I want to equate the two, and solve for deltaT at the minimum, so:
0=JC_stress1-JC_stress2

In MATLAB, i've written this in explicity:
function_min=@(deltaT)(A+B*strain^n)*(1+C*log(edot_star))*(1-(deltaT/(Tm-T0))^m)-(deltaT*rho*cp)/(xeta*strain);

And then submitted the function to fminsearch:
[deltaT,JC_stress] = fminsearch(function_min,1);

I get:
Exiting: Maximum number of function evaluations has been exceeded
         - increase MaxFunEvals option.
         Current function value: -26537838157353597000000000000000000000.000000

I don't understand why this isn't being solved correctly. If i plot the two functions JC_stress1 and JC_stress2 in terms of deltaT, they have a single clear intercept (which, to my understanding should be the solution to the fminsearch).

Any help would be greatly appreciated!!

Subject: fminsearch not finding a basic minimum

From: Shannon

Date: 3 Feb, 2011 23:41:04

Message: 2 of 8

ok....simple solution to a simple question - I didn't realize that fminsearch would look for negative solutions. I just had to use the absolute value of the function and it worked perfectly.

Subject: fminsearch not finding a basic minimum

From: Phil Goddard

Date: 3 Feb, 2011 23:49:04

Message: 3 of 8

or use fzero instead of fminsearch

Phil.

Subject: fminsearch not finding a basic minimum

From: Think blue, count two.

Date: 4 Feb, 2011 17:52:02

Message: 4 of 8

On 03/02/11 5:41 PM, Shannon wrote:
> ok....simple solution to a simple question - I didn't realize that
> fminsearch would look for negative solutions. I just had to use the
> absolute value of the function and it worked perfectly.

Don't use the absolute value of the function. Absolute value is not
differentiable, as is required for the functions submitted to nearly all
of the minimizers. Squaring the value of the function works, though, as
it *is* differentiable.

Subject: fminsearch not finding a basic minimum

From: Alan Weiss

Date: 4 Feb, 2011 19:31:21

Message: 5 of 8

On 2/4/2011 12:52 PM, Think blue, count two. wrote:
> On 03/02/11 5:41 PM, Shannon wrote:
>> ok....simple solution to a simple question - I didn't realize that
>> fminsearch would look for negative solutions. I just had to use the
>> absolute value of the function and it worked perfectly.
>
> Don't use the absolute value of the function. Absolute value is not
> differentiable, as is required for the functions submitted to nearly all
> of the minimizers. Squaring the value of the function works, though, as
> it *is* differentiable.

Differentiability is, indeed, required by most Optimization Toolbox
solvers. However, fminsearch does not use or need derivatives, so taking
absolute values is just fine. The algorithm is described here:
http://www.mathworks.com/help/techdoc/math/bsotu2d.html#bsgpq6p-11

Alan Weiss
MATLAB mathematical toolbox documentation

Subject: fminsearch not finding a basic minimum

From: Miroslav Balda

Date: 5 Feb, 2011 21:20:04

Message: 6 of 8

"Shannon" wrote in message <iifd74$hnp$1@fred.mathworks.com>...
> This is my first shot at applying one of the built-in minimization functions within MATLAB, and i'm getting a puzzling result that the command seems to be unable to find the minimum of a simple function.
>
> To start with, I have two functions:
> JC_stress1=(A+B*strain^n)*(1+C*ln(edot_star))*(1-(deltaT/(Tm-T0))^m);
> JC_stress2=(deltaT*rho*cp)/(xeta*strain);
> where A, B, C, n, m, Tm, T0, rho, cp, xeta, edot_star and strain are all constants
>
> I want to equate the two, and solve for deltaT at the minimum, so:
> 0=JC_stress1-JC_stress2
>
> In MATLAB, i've written this in explicity:
> function_min=@(deltaT)(A+B*strain^n)*(1+C*log(edot_star))*(1-(deltaT/(Tm-T0))^m)-(deltaT*rho*cp)/(xeta*strain);
>
> And then submitted the function to fminsearch:
> [deltaT,JC_stress] = fminsearch(function_min,1);
>
> I get:
> Exiting: Maximum number of function evaluations has been exceeded
> - increase MaxFunEvals option.
> Current function value: -26537838157353597000000000000000000000.000000
>
> I don't understand why this isn't being solved correctly. If i plot the two functions JC_stress1 and JC_stress2 in terms of deltaT, they have a single clear intercept (which, to my understanding should be the solution to the fminsearch).
>
> Any help would be greatly appreciated!!

Hi Shannon,
Nobody can guarantee that the result from any optimization procedure is 100% perfect, if no good guess of the solution is known. Hence, even divergence may occur, even if you prepare the code with a maximum care.
Your equation, if simplified, may be rewritten into the form
      u*(x^2)^m - v*x^2 = 0
I've prepared a simple code to demonstrate the behaviour of two functions - fminsearch and LMFnlsq from FEX
      www.mathworks.com/matlabcentral/fileexchange/17534
Having no real data to calculate constants m, u and v, I generated them as random.
You may see different solutions from both functions. The function fminsearch sometimes ends with infinite solution, sometimes with the solution deltaT=0. In case that the initial guess is far from the solution, the solution diverges.
The function LMFnlsq finds even the nontrivial solution in few iterations. You may experiment with it.
The control value of the while cycle is generated with the use of the function inp:
      www.mathworks.com/matlabcentral/fileexchange/9033
If you confirm the answer 'yes' by pressing ENTER, a next solutions from both functions are found based on a new set of m, u, v constants, the same for both functions. if you enter something else, the cycle finishes.
I hope that it will show you that there may be different results starting with the same parameters.
Good luck,

Mira

Subject: fminsearch not finding a basic minimum

From: Miroslav Balda

Date: 5 Feb, 2011 21:44:03

Message: 7 of 8

Sorry,
I have forgotten to attach the code I am speaking in the previous mail. Here it is:

while strcmp(inp('*********** Continue ***********','yes'),'yes')
    m = rand;
    u = rand;
    v = rand;
    res = @(x) u*(x^2)^m - v*x^2;
    x0 = rand;
    x = fminsearch(res,x0)
    deltaT = sqrt(x)
    r1 = res(x)
    
    disp('----------------')
    [x,ssq,cnt] = LMFnlsq(res,x0,'Xtol',1e-10)
    deltaT = x*x
    r2 = res(x)
end

Mira

Subject: fminsearch not finding a basic minimum

From: Shannon

Date: 7 Feb, 2011 01:02:04

Message: 8 of 8

Thanks for all your suggestions. As Alan pointed out, the fminsolve function is a derivitive-free method so i've stuck with the original approach of just using the absolute value.
There isn't too much range in the variables, so the added complexity of the LMFnlsq function that Mira described is probably not worth it for this case, but i've downloaded a copy of the .m file to use for more complex problems in the future.

Again....thanks everyone for your helpful solutions!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us