<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.fr/matlabcentral/newsreader/view_thread/289389</link>
    <title>MATLAB Central Newsreader - Finding all roots of a logarithm function (with parameters)</title>
    <description>Feed for thread: Finding all roots of a logarithm function (with parameters)</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2013 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.fr/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Mon, 16 Aug 2010 02:24:04 +0000</pubDate>
      <title>Finding all roots of a logarithm function (with parameters)</title>
      <link>http://www.mathworks.fr/matlabcentral/newsreader/view_thread/289389#771666</link>
      <author>summersyu Yu</author>
      <description>Hi,&lt;br&gt;
&lt;br&gt;
I want to find all roots of a non linear function as follows:&lt;br&gt;
&lt;br&gt;
a*log(1+x)-c*x=b, where a,b,c are parameters and x is the variable.&lt;br&gt;
&lt;br&gt;
The difficulty is to find all roots (sometimes 1 root and sometimes two roots). &lt;br&gt;
The following are methods that I have tried:&lt;br&gt;
&lt;br&gt;
1) a=5;c=1;b=3;&lt;br&gt;
subs(solve('a*log(1+x)-c*x=b'))&lt;br&gt;
&lt;br&gt;
It only returns one root.&lt;br&gt;
&lt;br&gt;
2) function y=parameterfun(x,a,b,c)&lt;br&gt;
y=a*log(1+x)-c*x-b&lt;br&gt;
&lt;br&gt;
a=5;c=1;b=3;&lt;br&gt;
fh=@(x)parameterfun(x,a,b,c)&lt;br&gt;
fsolve(fh,0)&lt;br&gt;
&lt;br&gt;
But it only returns one root.&lt;br&gt;
&lt;br&gt;
Is there any function in matlab that can return all roots?&lt;br&gt;
&lt;br&gt;
Thanks a lot!&lt;br&gt;
&amp;nbsp;</description>
    </item>
    <item>
      <pubDate>Mon, 16 Aug 2010 03:38:04 +0000</pubDate>
      <title>Re: Finding all roots of a logarithm function (with parameters)</title>
      <link>http://www.mathworks.fr/matlabcentral/newsreader/view_thread/289389#771676</link>
      <author>Roger Stafford</author>
      <description>"summersyu Yu" &amp;lt;summersyu@gmail.com&amp;gt; wrote in message &amp;lt;i4a7g4$3kg$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I want to find all roots of a non linear function as follows:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; a*log(1+x)-c*x=b, where a,b,c are parameters and x is the variable.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The difficulty is to find all roots (sometimes 1 root and sometimes two roots). &lt;br&gt;
&amp;gt; The following are methods that I have tried:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 1) a=5;c=1;b=3;&lt;br&gt;
&amp;gt; subs(solve('a*log(1+x)-c*x=b'))&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; It only returns one root.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 2) function y=parameterfun(x,a,b,c)&lt;br&gt;
&amp;gt; y=a*log(1+x)-c*x-b&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; a=5;c=1;b=3;&lt;br&gt;
&amp;gt; fh=@(x)parameterfun(x,a,b,c)&lt;br&gt;
&amp;gt; fsolve(fh,0)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; But it only returns one root.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Is there any function in matlab that can return all roots?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks a lot!&lt;br&gt;
- - - - - - - - - - -&lt;br&gt;
&amp;nbsp;&amp;nbsp;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.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;The reasoning goes this way:&lt;br&gt;
&lt;br&gt;
a*log(1+x)-c*x=b&lt;br&gt;
x+1 = exp((c*x+b)/a)&lt;br&gt;
&lt;br&gt;
Define w = -c/a*(x+1)&lt;br&gt;
&lt;br&gt;
x+1 = -a/c*w&lt;br&gt;
(c*x+b)/a = -w+(b-c)/a&lt;br&gt;
-a/c*w = exp(-w+(b-c)/a)&lt;br&gt;
w*exp(w) = -c/a*exp((b-c)/a)&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;You can read about the lambert W function at:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&lt;a href="http://en.wikipedia.org/wiki/Lambert_W_function"&gt;http://en.wikipedia.org/wiki/Lambert_W_function&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
Roger Stafford</description>
    </item>
    <item>
      <pubDate>Mon, 16 Aug 2010 04:59:45 +0000</pubDate>
      <title>Re: Finding all roots of a logarithm function (with parameters)</title>
      <link>http://www.mathworks.fr/matlabcentral/newsreader/view_thread/289389#771683</link>
      <author>Walter Roberson</author>
      <description>summersyu Yu wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt; I want to find all roots of a non linear function as follows:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; a*log(1+x)-c*x=b, where a,b,c are parameters and x is the variable.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The difficulty is to find all roots (sometimes 1 root and sometimes two &lt;br&gt;
&amp;gt; roots).&lt;br&gt;
&lt;br&gt;
I do not have an algebraic proof, but it appears that the two roots are &lt;br&gt;
related by being on the principle branch (k=0) and first negative branch &lt;br&gt;
(k=-1) of the same value:&lt;br&gt;
&lt;br&gt;
exp(-(a*LambertW(-c/a*exp((-c+b)/a))+c-b)/a)-1&lt;br&gt;
&lt;br&gt;
and&lt;br&gt;
&lt;br&gt;
exp(-(a*LambertW(-1, -c/a*exp((-c+b)/a))+c-b)/a)-1&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Whether there is one root or two roots appears to depend on the sign of &lt;br&gt;
a*c and upon whether a &amp;lt; b... though I think I have partly gotten myself &lt;br&gt;
confused over whether there are two roots or two *real* roots.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
I am encountering inconsistencies in Maple as to whether the k=-1 branch &lt;br&gt;
is a solution for a=5, b=3, c=2 -- some ways of evaluating it say that &lt;br&gt;
it is, and some ways say that it isn't, with the preponderance of &lt;br&gt;
evidence that it _is_ a root.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
In any case, I do not presently know of any mechanical way to return all &lt;br&gt;
of the roots with certainty.</description>
    </item>
    <item>
      <pubDate>Tue, 17 Aug 2010 15:30:21 +0000</pubDate>
      <title>Re: Finding all roots of a logarithm function (with parameters)</title>
      <link>http://www.mathworks.fr/matlabcentral/newsreader/view_thread/289389#772143</link>
      <author>summersyu Yu</author>
      <description>"Roger Stafford" &amp;lt;ellieandrogerxyzzy@mindspring.com.invalid&amp;gt; wrote in message &amp;lt;i4abqs$9t7$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; "summersyu Yu" &amp;lt;summersyu@gmail.com&amp;gt; wrote in message &amp;lt;i4a7g4$3kg$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Hi,&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; I want to find all roots of a non linear function as follows:&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; a*log(1+x)-c*x=b, where a,b,c are parameters and x is the variable.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; The difficulty is to find all roots (sometimes 1 root and sometimes two roots). &lt;br&gt;
&amp;gt; &amp;gt; The following are methods that I have tried:&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; 1) a=5;c=1;b=3;&lt;br&gt;
&amp;gt; &amp;gt; subs(solve('a*log(1+x)-c*x=b'))&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; It only returns one root.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; 2) function y=parameterfun(x,a,b,c)&lt;br&gt;
&amp;gt; &amp;gt; y=a*log(1+x)-c*x-b&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; a=5;c=1;b=3;&lt;br&gt;
&amp;gt; &amp;gt; fh=@(x)parameterfun(x,a,b,c)&lt;br&gt;
&amp;gt; &amp;gt; fsolve(fh,0)&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; But it only returns one root.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Is there any function in matlab that can return all roots?&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Thanks a lot!&lt;br&gt;
&amp;gt; - - - - - - - - - - -&lt;br&gt;
&amp;gt;   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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;   The reasoning goes this way:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; a*log(1+x)-c*x=b&lt;br&gt;
&amp;gt; x+1 = exp((c*x+b)/a)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Define w = -c/a*(x+1)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; x+1 = -a/c*w&lt;br&gt;
&amp;gt; (c*x+b)/a = -w+(b-c)/a&lt;br&gt;
&amp;gt; -a/c*w = exp(-w+(b-c)/a)&lt;br&gt;
&amp;gt; w*exp(w) = -c/a*exp((b-c)/a)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;   You can read about the lambert W function at:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;  &lt;a href="http://en.wikipedia.org/wiki/Lambert_W_function"&gt;http://en.wikipedia.org/wiki/Lambert_W_function&lt;/a&gt;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Roger Stafford&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Hi Roger,&lt;br&gt;
&lt;br&gt;
I found that the two roots have the following forms:&lt;br&gt;
&lt;br&gt;
root1=-a/c*lambertw(-c/a*exp(b-c)/a)-1;&lt;br&gt;
root2=-a/c*lambertw(-1,-c/a*exp(b-c)/a)-1;&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
Junqi</description>
    </item>
    <item>
      <pubDate>Tue, 17 Aug 2010 18:02:05 +0000</pubDate>
      <title>Re: Finding all roots of a logarithm function (with parameters)</title>
      <link>http://www.mathworks.fr/matlabcentral/newsreader/view_thread/289389#772195</link>
      <author>Roger Stafford</author>
      <description>"summersyu Yu" &amp;lt;summersyu@gmail.com&amp;gt; wrote in message &amp;lt;i4e9ud$oqj$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I found that the two roots have the following forms:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; root1=-a/c*lambertw(-c/a*exp(b-c)/a)-1;&lt;br&gt;
&amp;gt; root2=-a/c*lambertw(-1,-c/a*exp(b-c)/a)-1;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks,&lt;br&gt;
&amp;gt; Junqi&lt;br&gt;
- - - - - - - - - -&lt;br&gt;
&amp;nbsp;&amp;nbsp;Yes, those expressions follow easily from the two equations&lt;br&gt;
&lt;br&gt;
&amp;nbsp;x+1 = -a/c*w&lt;br&gt;
&lt;br&gt;
and&lt;br&gt;
&lt;br&gt;
&amp;nbsp;w*exp(w) = -c/a*exp((b-c)/a)&lt;br&gt;
&lt;br&gt;
which I derived for you.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;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 &amp;lt;= x.  A second branch denoted by k = -1 gives a real value for -1/e &amp;lt;= x &amp;lt; 0.  Real values out of these ranges for these two branches and for all real values of other branches give complex results.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;You might be interested in further reading on the subject at one of these sites:&lt;br&gt;
&lt;br&gt;
&lt;a href="http://en.wikipedia.org/wiki/Lambert_W_function"&gt;http://en.wikipedia.org/wiki/Lambert_W_function&lt;/a&gt;&lt;br&gt;
&lt;a href="http://mathworld.wolfram.com/LambertW-Function.html"&gt;http://mathworld.wolfram.com/LambertW-Function.html&lt;/a&gt;&lt;br&gt;
&lt;a href="http://www.math.ucla.edu/~getreuer/lambertw.html"&gt;http://www.math.ucla.edu/~getreuer/lambertw.html&lt;/a&gt;&lt;br&gt;
&lt;a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.86.9305&amp;rep=rep1&amp;type=pdf"&gt;http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.86.9305&amp;rep=rep1&amp;type=pdf&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
Roger Stafford</description>
    </item>
    <item>
      <pubDate>Tue, 17 Aug 2010 18:23:40 +0000</pubDate>
      <title>Re: Finding all roots of a logarithm function (with parameters)</title>
      <link>http://www.mathworks.fr/matlabcentral/newsreader/view_thread/289389#772203</link>
      <author>Walter Roberson</author>
      <description>summersyu Yu wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt; I found that the two roots have the following forms:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; root1=-a/c*lambertw(-c/a*exp(b-c)/a)-1;&lt;br&gt;
&amp;gt; root2=-a/c*lambertw(-1,-c/a*exp(b-c)/a)-1;&lt;br&gt;
&lt;br&gt;
Were you able to prove that, or did you extract that from my earlier response &lt;br&gt;
where I indicated without proof that those were the only forms I found?&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&amp;gt; What is the branch argument -1? In the help, it says "the K-th branch of &lt;br&gt;
&amp;gt; this multi-valued function". But I do not understand why it is -1 not &lt;br&gt;
&amp;gt; other values.&lt;br&gt;
&lt;br&gt;
I don't know why -1 and not something else; the -1 is what I found experimentally.&lt;br&gt;
&lt;br&gt;
As to what it means, see the following from the Maple help for LambertW:&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
o The principal branch and the pair of branches LambertW(-1, x) and &lt;br&gt;
LambertW(1, x) share an order 2 branch point at -exp(-1). The branch cut &lt;br&gt;
dividing these branches is the subset of the real line from -infinity to &lt;br&gt;
-exp(-1), and the values of the branches of LambertW on this branch cut are &lt;br&gt;
assigned using the rule of counter-clockwise continuity around the branch &lt;br&gt;
point. This means that LambertW(x) is real-valued for x in the range -exp(-1) &lt;br&gt;
.. infinity, while the image of -infinity .. -exp(-1) under LambertW(x) is the &lt;br&gt;
curve -y*cot(y)+I*y, for y in 0 .. Pi.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;Similarly, the branch corresponding to -1, LambertW(-1, x), is real-valued &lt;br&gt;
on the interval -exp(-1) .. 0, while the image of -infinity .. -exp(-1) under &lt;br&gt;
this branch is the curve -y*cot(y)+I*y, for y in -Pi .. 0.&lt;br&gt;
&lt;br&gt;
o For all the branches other than the principal branch, the branch cut &lt;br&gt;
dividing them is the negative real axis. The branches are numbered up and down &lt;br&gt;
from the real axis (this is very similar to the way the branches of the &lt;br&gt;
logarithm are indexed by the multiple of (2*I)*Pi which must be subtracted &lt;br&gt;
from the imaginary part to recover the principal branch). Again, the values of &lt;br&gt;
the branches of LambertW along the branch cut are determined by the rule of &lt;br&gt;
counter-clockwise continuity around the branch point at 0. Thus, the image of &lt;br&gt;
the negative real axis under the branch LambertW(k, x) is the curve &lt;br&gt;
-y*cot(y)+I*y, for y in 2*k*Pi .. (2*k+1)*Pi if 0 &amp;lt; k and y in (2*k+1)*Pi .. &lt;br&gt;
(2*k+2)*Pi if k &amp;lt; -1. These curves, therefore, bound the ranges of the &lt;br&gt;
branches of LambertW, and in each case, the upper boundary of the region is &lt;br&gt;
included in the range of the corresponding branch.</description>
    </item>
  </channel>
</rss>
