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 involving incomplete gamma function

Subject: fminsearch involving incomplete gamma function

From: edward kabanyas

Date: 13 Apr, 2009 11:22:01

Message: 1 of 5

Dear All,

I am tring to find the parameters of the following equation:

function f = myfun(x,eta,Dmax, Dmin)

f =((gamma(x(1)+4)*gammainc(x(2)*Dmax,x(1)+4,'lower')-(1-gammainc(x(2)*Dmin,x(1)+4, 'upper')))^2./((gamma(x(1)+5)*gammainc(x(2)*Dmax,x(1)+5,'lower')-(1-gammainc(x(2)*Dmin,x(1)+5, 'upper')))*(gamma(x(1)+3)*gammainc(x(2)*Dmax,x(1)+3, 'lower')-(1-gammainc(x(2)*Dmin,x(1)+3, 'upper')))))-eta;

eta, Dmax and Dmin are given. We can see that the above equation involving the incomplete gamma function.

When I run the fminserach as:

 xval = fminsearch(@(x)myfun(x,eta,Dmax, Dmin), x);

The following error is alway occurs:

??? Error using ==> gammainc
A must be non-negative.

Error in ==> myfun at 3
f =((gamma(x(1)+4)*gammainc(x(2)*Dmax,x(1)+4,'lower')-(1-gammainc(x(2)*Dmin,x(1)+4, 'upper')))^2./((gamma(x(1)+5)*gammainc(x(2)*Dmax,x(1)+5,'lower')-(1-gammainc(x(2)*Dmin,x(1)+5, 'upper')))*(gamma(x(
Error in ==> @(x)myfun(x,eta,Dmax, Dmin),

Friends, do you have any suggestion to solve this problem and can we accsee the matlab code of fminsearch.m??

Thanks so mcuh.

Cheers
David

Subject: fminsearch involving incomplete gamma function

From: John D'Errico

Date: 13 Apr, 2009 12:36:02

Message: 2 of 5

"edward kabanyas" <djuky_hmi@yahoo.com> wrote in message <grv78p$lud$1@fred.mathworks.com>...
> Dear All,
>
> I am tring to find the parameters of the following equation:
>
> function f = myfun(x,eta,Dmax, Dmin)

(snip)

> ??? Error using ==> gammainc
> A must be non-negative.
>
> Error in ==> myfun at 3
> f =((gamma(x(1)+4)*gammainc(x(2)*Dmax,x(1)+4,'lower')-(1-gammainc(x(2)*Dmin,x(1)+4, 'upper')))^2./((gamma(x(1)+5)*gammainc(x(2)*Dmax,x(1)+5,'lower')-(1-gammainc(x(2)*Dmin,x(1)+5, 'upper')))*(gamma(x(
> Error in ==> @(x)myfun(x,eta,Dmax, Dmin),
>
> Friends, do you have any suggestion to solve this problem and can we accsee the matlab code of fminsearch.m??
>

Nothing stops you from looking...

type fminsearch

But nothing stops fminsearch from trying negative
values the parameters. And apparently, it wants to
look in that direction.

A solution is to use a bounded solver. Find one
here:

http://www.mathworks.com/matlabcentral/fileexchange/8277

HTH,
John

Subject: fminsearch involving incomplete gamma function

From: edward kabanyas

Date: 13 Apr, 2009 18:19:01

Message: 3 of 5

Dear Jhon;

Thanks very much for your comment.

I try your code, but it seems the result not what I want. Because I try to use fminsearch to the following equation:

f = x^2 + x - 12;

Matlab output is:

xval =

   -0.5000


fval =

  -12.2500

Actually what I want is: xval = 3 or -4. So what I want is the value give the f = 0. I thought the fminsearch will give me what I need. So from the following equation:

f = ((gamma(xx(1)+4)*(gammainc(xx(2)*Dmax,xx(1)+4,'lower')-(1-gammainc(xx(2)*Dmin,xx(1)+4, 'upper'))))^2./((gamma(xx(1)+5)*(gammainc(xx(2)*Dmax,xx(1)+5,'lower')-(1-gammainc(xx(2)*Dmin,xx(1)+5, 'upper'))))*(gamma(xx(1)+3)*(gammainc(xx(2)*Dmax,xx(1)+3,'lower')-(1-gammainc(xx(2)*Dmin,xx(1)+3, 'upper'))))))-eta;

I need x that result f close to 0 in which Dmax, Dmin, eta, and initial x are given. Dr Jhon, do you have any suggestion for me ?

Thanks for nice help.

Chhers
Davids

Subject: fminsearch involving incomplete gamma function

From: Alan Weiss

Date: 13 Apr, 2009 18:47:49

Message: 4 of 5

Is it possible you are trying to solve an equation rather than minimize
a function? If so, look at the documentation for fzero.
doc fzero
or
http://www.mathworks.com/access/helpdesk/help/techdoc/math/f2-14970.html#f2-943601

Alan Weiss
MATLAB mathematical toolbox documentation

edward kabanyas wrote:
> Dear Jhon;
>
> Thanks very much for your comment.
>
> I try your code, but it seems the result not what I want. Because I try to use fminsearch to the following equation:
>
> f = x^2 + x - 12;
>
> Matlab output is:
>
> xval =
>
> -0.5000
>
>
> fval =
>
> -12.2500
>
> Actually what I want is: xval = 3 or -4. So what I want is the value give the f = 0. I thought the fminsearch will give me what I need. So from the following equation:
>
> f = ((gamma(xx(1)+4)*(gammainc(xx(2)*Dmax,xx(1)+4,'lower')-(1-gammainc(xx(2)*Dmin,xx(1)+4, 'upper'))))^2./((gamma(xx(1)+5)*(gammainc(xx(2)*Dmax,xx(1)+5,'lower')-(1-gammainc(xx(2)*Dmin,xx(1)+5, 'upper'))))*(gamma(xx(1)+3)*(gammainc(xx(2)*Dmax,xx(1)+3,'lower')-(1-gammainc(xx(2)*Dmin,xx(1)+3, 'upper'))))))-eta;
>
> I need x that result f close to 0 in which Dmax, Dmin, eta, and initial x are given. Dr Jhon, do you have any suggestion for me ?
>
> Thanks for nice help.
>
> Chhers
> Davids

Subject: fminsearch involving incomplete gamma function

From: edward kabanyas

Date: 14 Apr, 2009 04:48:01

Message: 5 of 5

Dear Allan;

It is difficult to solve the equation numerically. I trid to use fzero but fzero is only for one variable, my variables are two. And then I tried to use fsolve but I get the following error:

Default trust-region dogleg method of FSOLVE cannot
 handle non-square systems; switching to Gauss-Newton method.
> In fsolve at 232

Regards;
david

Alan Weiss <aweiss@mathworks.com> wrote in message <gs01cl$fin$1@fred.mathworks.com>...
> Is it possible you are trying to solve an equation rather than minimize
> a function? If so, look at the documentation for fzero.
> doc fzero
> or
> http://www.mathworks.com/access/helpdesk/help/techdoc/math/f2-14970.html#f2-943601
>
> Alan Weiss
> MATLAB mathematical toolbox documentation
>
> edward kabanyas wrote:
> > Dear Jhon;
> >
> > Thanks very much for your comment.
> >
> > I try your code, but it seems the result not what I want. Because I try to use fminsearch to the following equation:
> >
> > f = x^2 + x - 12;
> >
> > Matlab output is:
> >
> > xval =
> >
> > -0.5000
> >
> >
> > fval =
> >
> > -12.2500
> >
> > Actually what I want is: xval = 3 or -4. So what I want is the value give the f = 0. I thought the fminsearch will give me what I need. So from the following equation:
> >
> > f = ((gamma(xx(1)+4)*(gammainc(xx(2)*Dmax,xx(1)+4,'lower')-(1-gammainc(xx(2)*Dmin,xx(1)+4, 'upper'))))^2./((gamma(xx(1)+5)*(gammainc(xx(2)*Dmax,xx(1)+5,'lower')-(1-gammainc(xx(2)*Dmin,xx(1)+5, 'upper'))))*(gamma(xx(1)+3)*(gammainc(xx(2)*Dmax,xx(1)+3,'lower')-(1-gammainc(xx(2)*Dmin,xx(1)+3, 'upper'))))))-eta;
> >
> > I need x that result f close to 0 in which Dmax, Dmin, eta, and initial x are given. Dr Jhon, do you have any suggestion for me ?
> >
> > Thanks for nice help.
> >
> > Chhers
> > Davids

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