Got Questions? Get Answers.
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:
Finding all roots of a logarithm function (with parameters)

Subject: Finding all roots of a logarithm function (with parameters)

From: summersyu Yu

Date: 16 Aug, 2010 02:24:04

Message: 1 of 6

Hi,

I want to find all roots of a non linear function as follows:

a*log(1+x)-c*x=b, where a,b,c are parameters and x is the variable.

The difficulty is to find all roots (sometimes 1 root and sometimes two roots).
The following are methods that I have tried:

1) a=5;c=1;b=3;
subs(solve('a*log(1+x)-c*x=b'))

It only returns one root.

2) function y=parameterfun(x,a,b,c)
y=a*log(1+x)-c*x-b

a=5;c=1;b=3;
fh=@(x)parameterfun(x,a,b,c)
fsolve(fh,0)

But it only returns one root.

Is there any function in matlab that can return all roots?

Thanks a lot!
 

Subject: Finding all roots of a logarithm function (with parameters)

From: Roger Stafford

Date: 16 Aug, 2010 03:38:04

Message: 2 of 6

"summersyu Yu" <summersyu@gmail.com> wrote in message <i4a7g4$3kg$1@fred.mathworks.com>...
> Hi,
>
> I want to find all roots of a non linear function as follows:
>
> a*log(1+x)-c*x=b, where a,b,c are parameters and x is the variable.
>
> The difficulty is to find all roots (sometimes 1 root and sometimes two roots).
> The following are methods that I have tried:
>
> 1) a=5;c=1;b=3;
> subs(solve('a*log(1+x)-c*x=b'))
>
> It only returns one root.
>
> 2) function y=parameterfun(x,a,b,c)
> y=a*log(1+x)-c*x-b
>
> a=5;c=1;b=3;
> fh=@(x)parameterfun(x,a,b,c)
> fsolve(fh,0)
>
> But it only returns one root.
>
> Is there any function in matlab that can return all roots?
>
> Thanks a lot!
- - - - - - - - - - -
  This problem can be posed in terms of the lambert function, and matlab's symbolic toolbox has a lambertw function you can use which will give more than one root for it if you ask for it. Use the "branch" argument.

  The reasoning goes this way:

a*log(1+x)-c*x=b
x+1 = exp((c*x+b)/a)

Define w = -c/a*(x+1)

x+1 = -a/c*w
(c*x+b)/a = -w+(b-c)/a
-a/c*w = exp(-w+(b-c)/a)
w*exp(w) = -c/a*exp((b-c)/a)

This is in the form required by lambertw. After you find w, you can then compute x from it as x = -a/c*w-1.

  You can read about the lambert W function at:

 http://en.wikipedia.org/wiki/Lambert_W_function

Roger Stafford

Subject: Finding all roots of a logarithm function (with parameters)

From: Walter Roberson

Date: 16 Aug, 2010 04:59:45

Message: 3 of 6

summersyu Yu wrote:

> I want to find all roots of a non linear function as follows:
>
> a*log(1+x)-c*x=b, where a,b,c are parameters and x is the variable.
>
> The difficulty is to find all roots (sometimes 1 root and sometimes two
> roots).

I do not have an algebraic proof, but it appears that the two roots are
related by being on the principle branch (k=0) and first negative branch
(k=-1) of the same value:

exp(-(a*LambertW(-c/a*exp((-c+b)/a))+c-b)/a)-1

and

exp(-(a*LambertW(-1, -c/a*exp((-c+b)/a))+c-b)/a)-1


Whether there is one root or two roots appears to depend on the sign of
a*c and upon whether a < b... though I think I have partly gotten myself
confused over whether there are two roots or two *real* roots.


I am encountering inconsistencies in Maple as to whether the k=-1 branch
is a solution for a=5, b=3, c=2 -- some ways of evaluating it say that
it is, and some ways say that it isn't, with the preponderance of
evidence that it _is_ a root.


In any case, I do not presently know of any mechanical way to return all
of the roots with certainty.

Subject: Finding all roots of a logarithm function (with parameters)

From: summersyu Yu

Date: 17 Aug, 2010 15:30:21

Message: 4 of 6

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i4abqs$9t7$1@fred.mathworks.com>...
> "summersyu Yu" <summersyu@gmail.com> wrote in message <i4a7g4$3kg$1@fred.mathworks.com>...
> > Hi,
> >
> > I want to find all roots of a non linear function as follows:
> >
> > a*log(1+x)-c*x=b, where a,b,c are parameters and x is the variable.
> >
> > The difficulty is to find all roots (sometimes 1 root and sometimes two roots).
> > The following are methods that I have tried:
> >
> > 1) a=5;c=1;b=3;
> > subs(solve('a*log(1+x)-c*x=b'))
> >
> > It only returns one root.
> >
> > 2) function y=parameterfun(x,a,b,c)
> > y=a*log(1+x)-c*x-b
> >
> > a=5;c=1;b=3;
> > fh=@(x)parameterfun(x,a,b,c)
> > fsolve(fh,0)
> >
> > But it only returns one root.
> >
> > Is there any function in matlab that can return all roots?
> >
> > Thanks a lot!
> - - - - - - - - - - -
> This problem can be posed in terms of the lambert function, and matlab's symbolic toolbox has a lambertw function you can use which will give more than one root for it if you ask for it. Use the "branch" argument.
>
> The reasoning goes this way:
>
> a*log(1+x)-c*x=b
> x+1 = exp((c*x+b)/a)
>
> Define w = -c/a*(x+1)
>
> x+1 = -a/c*w
> (c*x+b)/a = -w+(b-c)/a
> -a/c*w = exp(-w+(b-c)/a)
> w*exp(w) = -c/a*exp((b-c)/a)
>
> This is in the form required by lambertw. After you find w, you can then compute x from it as x = -a/c*w-1.
>
> You can read about the lambert W function at:
>
> http://en.wikipedia.org/wiki/Lambert_W_function
>
> Roger Stafford


Hi Roger,

I found that the two roots have the following forms:

root1=-a/c*lambertw(-c/a*exp(b-c)/a)-1;
root2=-a/c*lambertw(-1,-c/a*exp(b-c)/a)-1;

What is the branch argument -1? In the help, it says "the K-th branch of this multi-valued function". But I do not understand why it is -1 not other values.

Thanks,
Junqi

Subject: Finding all roots of a logarithm function (with parameters)

From: Roger Stafford

Date: 17 Aug, 2010 18:02:05

Message: 5 of 6

"summersyu Yu" <summersyu@gmail.com> wrote in message <i4e9ud$oqj$1@fred.mathworks.com>...
> I found that the two roots have the following forms:
>
> root1=-a/c*lambertw(-c/a*exp(b-c)/a)-1;
> root2=-a/c*lambertw(-1,-c/a*exp(b-c)/a)-1;
>
> What is the branch argument -1? In the help, it says "the K-th branch of this multi-valued function". But I do not understand why it is -1 not other values.
>
> Thanks,
> Junqi
- - - - - - - - - -
  Yes, those expressions follow easily from the two equations

 x+1 = -a/c*w

and

 w*exp(w) = -c/a*exp((b-c)/a)

which I derived for you.

  The 'k' in lambertw(k,x) can be any integer, negative as well as non-negative, and refers to the branch you wish to select. These are analogous to the infinitely many branches of log(z) in the complex plane. What is called the principal branch of the lambertw function denoted by k = 0 is real-valued for x real and -1/e <= x. A second branch denoted by k = -1 gives a real value for -1/e <= x < 0. Real values out of these ranges for these two branches and for all real values of other branches give complex results.

  You might be interested in further reading on the subject at one of these sites:

http://en.wikipedia.org/wiki/Lambert_W_function
http://mathworld.wolfram.com/LambertW-Function.html
http://www.math.ucla.edu/~getreuer/lambertw.html
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.86.9305&rep=rep1&type=pdf

Roger Stafford

Subject: Finding all roots of a logarithm function (with parameters)

From: Walter Roberson

Date: 17 Aug, 2010 18:23:40

Message: 6 of 6

summersyu Yu wrote:

> I found that the two roots have the following forms:
>
> root1=-a/c*lambertw(-c/a*exp(b-c)/a)-1;
> root2=-a/c*lambertw(-1,-c/a*exp(b-c)/a)-1;

Were you able to prove that, or did you extract that from my earlier response
where I indicated without proof that those were the only forms I found?


> What is the branch argument -1? In the help, it says "the K-th branch of
> this multi-valued function". But I do not understand why it is -1 not
> other values.

I don't know why -1 and not something else; the -1 is what I found experimentally.

As to what it means, see the following from the Maple help for LambertW:


o The principal branch and the pair of branches LambertW(-1, x) and
LambertW(1, x) share an order 2 branch point at -exp(-1). The branch cut
dividing these branches is the subset of the real line from -infinity to
-exp(-1), and the values of the branches of LambertW on this branch cut are
assigned using the rule of counter-clockwise continuity around the branch
point. This means that LambertW(x) is real-valued for x in the range -exp(-1)
.. infinity, while the image of -infinity .. -exp(-1) under LambertW(x) is the
curve -y*cot(y)+I*y, for y in 0 .. Pi.

   Similarly, the branch corresponding to -1, LambertW(-1, x), is real-valued
on the interval -exp(-1) .. 0, while the image of -infinity .. -exp(-1) under
this branch is the curve -y*cot(y)+I*y, for y in -Pi .. 0.

o For all the branches other than the principal branch, the branch cut
dividing them is the negative real axis. The branches are numbered up and down
from the real axis (this is very similar to the way the branches of the
logarithm are indexed by the multiple of (2*I)*Pi which must be subtracted
from the imaginary part to recover the principal branch). Again, the values of
the branches of LambertW along the branch cut are determined by the rule of
counter-clockwise continuity around the branch point at 0. Thus, the image of
the negative real axis under the branch LambertW(k, x) is the curve
-y*cot(y)+I*y, for y in 2*k*Pi .. (2*k+1)*Pi if 0 < k and y in (2*k+1)*Pi ..
(2*k+2)*Pi if k < -1. These curves, therefore, bound the ranges of the
branches of LambertW, and in each case, the upper boundary of the region is
included in the range of the corresponding branch.

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