2

Crank ("The mathematics of diffusion", 2nd editon, 1975, p.57) describes a diffusion modelling algorithm which relies on the non-zero positive roots of

$$ \tan{q_n} = -\alpha\cdot q_n$$

Typical values I use for $\alpha : 0.1, 1, 10, 15, 25, 50,... $

To achieve the necessary accuracy for small diffusion coefficients (e. g. $10^{-16} $) I need to calculate several hundred roots. I currently use Mathematica to calculate the roots, but this is a quite painful procedure. Therefore I would like to write a C++ program which will help me calculating the roots. For that I would need an algorithm to solve above equation. Any help with that would be appreciated.

whoever
  • 23
  • Welcome. MathJax supports backslashes for many purposes; e.g., $\tan$ should be rendered with \tan – FShrike Dec 04 '21 at 11:45
  • Based on some experimentation, for reasonably small values of $\alpha$, you can let $f(x)=\tan(x)+\alpha x$ and pick an initial guess of $x_0=2$ for Newton's method. Repeat the process as many times as needed, and then use $x_0=2+\pi$ for your next initial guess and find the next root. Then use $2+2\pi$ as your initial guess, then $2+3\pi$, etc. – K.defaoite Dec 04 '21 at 11:53
  • @K.defaoite: Thanks - very helpful :-) – whoever Dec 04 '21 at 14:10
  • There were a few mistakes. Sorry for that. Cheers :-) – Claude Leibovici Dec 06 '21 at 08:31
  • I suppose that with $\alpha=0.1$ it will not be very good. Try and let me know. – Claude Leibovici Dec 06 '21 at 13:10
  • @ClaudeLeibovici:I compared your analytical values with numerical values calculated with Mathematica. For α=0.1 there are considerable differences for n=0 to 2. For n = 3 the difference is 4.9%. For n = 4 difference decreased to 0.07%. Difference is decreasing further with higher values of n. For α=1 n = 0 is completely off. n = 1 is very close to the numerical value (8.26e-7%). From n = 3 analytical and numerical values are identically (resolution: 13 digits behind decimal point). – whoever Dec 06 '21 at 16:00
  • @whoever. All of that is normal. What you can do (in order to polish the root) is one iteration of Newton or Halley methods starting with the given estimate. – Claude Leibovici Dec 06 '21 at 16:04

1 Answers1

1

You are looking for the zero's of function $$f(x)=\tan(x)+\alpha x$$ They will be closer and closer to $(2n+1)\frac \pi 2$. To remove the unpleasant discontinuities, consider instead $$g(x)=\sin(x)+\alpha x \cos(x)$$ and use Taylor series around $x=(2n+1)\frac \pi 2$ $$g(x)=\frac 12\sum_{k=0}^\infty(-1)^n\frac{ 2 (\alpha k+1) \cos \left(\frac{\pi k}{2}\right)-\pi \alpha (2 n+1) \sin \left(\frac{\pi k}{2}\right)}{ k!}\Big[x- (2 n+1)\frac \pi 2\Big]^k$$ Truncate to some order and use series reversion to obtain fot the $n^{\text{th}}$ root $$x_{(n)}= t+\sum_{m=0}^p (-1)^{m}\frac {c_m} {(\alpha t)^{2m+1}}\qquad \text{where} \qquad t=(2n+1)\frac \pi 2$$

The first coefficients $c_m$ are $$\left( \begin{array}{cc} m & c_m \\ 0 & 1 \\ 1 & \alpha +\frac{1}{3} \\ 2 & 2 \alpha ^2+\frac{4 \alpha }{3}+\frac{1}{5} \\ 3 & 5 \alpha ^3+5 \alpha ^2+\frac{23 \alpha }{15}+\frac{1}{7} \\ 4 & 14 \alpha ^4+\frac{56 \alpha ^3}{3}+\frac{392 \alpha ^2}{45}+\frac{176 \alpha }{105}+\frac{1}{9} \\ 5 & 42 \alpha ^5+70 \alpha ^4+44 \alpha ^3+\frac{818 \alpha ^2}{63}+\frac{563 \alpha }{315}+\frac{1}{11} \\ 6 & 132 \alpha ^6+264 \alpha ^5+209 \alpha ^4+\frac{15796 \alpha ^3}{189}+\frac{3102 \alpha ^2}{175}+\frac{6508 \alpha }{3465}+\frac{61}{1024} \\ 7 & 429 \alpha ^7+1001 \alpha ^6+\frac{43043 \alpha ^5}{45}+\frac{65351 \alpha ^4}{135}+\frac{282841 \alpha ^3}{2025}+\frac{1534247 \alpha ^2}{57600}+\frac{141583 \alpha }{23040}+\frac{18811}{15360} \end{array} \right)$$

Trying for $\alpha=10$ with $p=7$

$$\left( \begin{array}{ccc} 0 &\color{red}{1.63199452}646140205048274685183 & 1.63199452721480006371688983888 \\ 1 & \color{red}{4.733511802356786}19428997112737 & 4.73351180235678620084907851480 \\ 2 & \color{red}{7.86669277156157419748}480845369 & 7.86669277156157419748592987705 \\ 3 & \color{red}{11.004661096033518512264}5971500 & 11.0046610960335185122646008382 \\ 4 & \color{red}{14.1442368407184333320452158}130 & 14.1442368407184333320452158645 \\ 5 & \color{red}{17.28454504550461827956001048}46 & 17.2845450455046182795600104863 \\ 6 & \color{red}{20.425248110576069042708349747}2 & 20.4252481105760690427083497473 \\ 7 & \color{red}{23.5661882440696287891706461263} & 23.5661882440696287891706461263 \end{array} \right)$$

Edit

If you are not looking for too much accuracy, rewrite

$$x_{(n)}= t+\sum_{m=0}^p (-1)^{m}\frac {c_m} {(\alpha t)^{2m+1}}=t+\frac 1 {\alpha t}\sum_{m=0}^p (-1)^{m} c_m \,y^m$$ with $y=\frac 1{(\alpha t)^2} $ and use the simplest Padé approximant $$\sum_{m=0}^p (-1)^{m} c_m \,y^m=\frac{c_0 c_1+\left(c_0 c_2-c_1^2\right) y } {c_1+c_2y }+O\left(y^3\right)$$

For $\alpha=10$ as above, the solutions will be $$\{1.631998,4.733512,7.866693,11.00466,14.14424,17.28455,20.42525,23.56619\}$$

  • Very nice indeed. – K.defaoite Dec 04 '21 at 15:35
  • First of all many thanks for the really nice derivation. You refined & expanded your answer compared with yesterday. I calculated some values with your equation yesterday (1.6320227505878306, 4.73351184288659, 7.866692774190552,...) which I think are consistent with the results you calculated. Today I tried to calculate some results for alpha = 10 and p = 3, but I came to results which are quite off. If I compare the equations from today with the equations you posted yesterday they do not seem to be identically. – whoever Dec 05 '21 at 08:48
  • @whoever. I shall rework and post. – Claude Leibovici Dec 06 '21 at 07:38
  • @ClaudeLeibovici: Many thanks for the update of your posting. The calculations now seem all to be ok and a nice touch to color the digits to show that the solution is getting closer and closer to the approximation. In order to make your answer more readable for other viewers I have two very small formal suggestions: you could again mention case c0 = 1 because it is part of the summation. The summation variable n could be replaced with some other variable, because it is not the n of x(n) and not the n mentioned in the equation for t (t could be labelled with n in the summation). – whoever Dec 06 '21 at 12:31
  • @ClaudeLeibovici: yes the answer is perfect now. Many thanks for your help with it. I just accepted it. :-) – whoever Dec 06 '21 at 12:58