I want to approximate tanh by a low-degree rational function of form r ( x )

Sylvia Byrd

Sylvia Byrd

Answered question

2022-07-04

I want to approximate tanh by a low-degree rational function of form
r ( x ) = p ( x ) q ( x ) = p 2 x 2 + p 1 x + p 0 q 1 x + q 0
such that the L 2 norm over the fixed interval [ x 0 , x 1 ] is small:
I ( p , q ) = 1 2 x 0 x 1 ( r ( x ) tanh ( x ) ) 2 d x .
That is, I would like to solve for the coefficients p 2 , p 1 , p 0 , q 1 , q 0 . Note that d e g ( p ) 2 and d e g ( q ) 1.
I don't know where to begin, so I'm looking for suggestions on how to approach this problem; pointers to relevant numerical methods would also be greatly appreciated

Answer & Explanation

Camron Herrera

Camron Herrera

Beginner2022-07-05Added 16 answers

Not an answer but too long for a comment.
An analytical expression of the L 2 norm seems very difficult (not to say impossible).
What I would suggest is to built the [ 2 , 1 ] Padé approximant of tanh ( x ) around a = x 0 + x 1 2 . This would give
tanh ( x ) = 3 tanh ( a ) + 2 ( x a ) + ( tanh ( a ) coth ( a ) ) ( x a ) 2 3 + ( 3 tanh ( a ) coth ( a ) ) ( x a ) + O ( ( x a ) 4 )
Trying for x 0 = 1 and x 1 = 2
1 2 [ tanh ( x ) Padé ] 2 d x = 3.90537 × 10 7
seems to be already decent. For the same problem, a full optimization would give 1.15644 × 10 8
2 3 [ tanh ( x ) Padé ] 2 d x = 8.80730 × 10 9
3 4 [ tanh ( x ) Padé ] 2 d x = 1.66518 × 10 10
log [ n n + 1 [ tanh ( x ) Padé ] 2 d x ] = 3.87288 n 11.2126
May be, you could use the sum of these Padé approximants each of them being built for a short interval.
Edit:
The key problem is that we cannot have even an explicit solution for
( tanh ( x ) a x b x + 1 ) 2 d x
There is one thing you could try taking into account the fact that the [ 2 , 1 ] Padé approximant is O ( ( x a ) 4 ) .
Let
tanh ( x ) = n = 0 3 b n ( x a ) n
and define the L 2 norm
Φ ( b 0 , b 1 , b 2 , b 3 ) = x 0 x 1 [ tanh ( x ) n = 0 3 b n ( x a ) n ] 2 d x
developing the integrand, we have terms in ( k = 0 , , 6 ) (no problem with these) and a series of integrals
I n = x n tanh ( x ) d x k = 0 , 1 , 2 , 3
They do not make much problems
I 0 = log ( cosh ( x ) )
I 1 = 1 2 ( x ( x + 2 log ( e 2 x + 1 ) ) Li 2 ( e 2 x ) )
I 2 = x Li 2 ( e 2 x ) 1 2 Li 3 ( e 2 x ) + x 3 3 + x 2 log ( e 2 x + 1 )
I 3 = 1 4 ( 6 x 2 Li 2 ( e 2 x ) 6 x Li 3 ( e 2 x ) 3 Li 4 ( e 2 x ) + x 4 + 4 x 3 log ( e 2 x + 1 ) )
and
tanh 2 ( x ) d x = x tanh ( x )
So, we have all the elements. Now solve
Φ b 0 = Φ b 1 = Φ b 2 = Φ b 3 = 0
which makes a linear system of four equations for four unknowns.
So, we have the series expansion that we could transform as a [ 2 , 1 ] Padé approximant around the midpoint a = x 0 + x 1 2
with
p 2 = b 2 2 b 1 b 3 p 1 = b 1 b 2 b 0 b 3 p 0 = b 0 b 2 q 1 = b 3 q 0 = b 2
This procedure has been tried with x 0 = 1, x 1 = 3, a = 2.
Using the original Padé approximant leads, for the L 2 norm, to a value equal to 1.67 × 10 4 . The optimization of the series gives 3.57 × 10 6 . The new Padé approximant leads to 3.33 × 10 4 .
Much work for a more than bad result.
rzfansubs87

rzfansubs87

Beginner2022-07-06Added 5 answers

Here is a (bad!) attempt. First, suppose without loss of generality that q 1 = 1, and define
Q ( k ) ( q 0 ) = x 0 x 1 x k tanh ( x ) x + q 0 d x ,
then expanding the optimality conditions p ( ) I = 0 we obtain
p 0 I = x 0 x 1 ( r ( x ) tanh ( x ) ) 1 x + q 0 d x = x 0 x 1 r ( x ) x + q 0 d x Q ( 0 ) ( q 0 ) = 0 p 1 I = x 0 x 1 ( r ( x ) tanh ( x ) ) x x + q 0 d x = x 0 x 1 x r ( x ) x + q 0 d x Q ( 1 ) ( q 0 ) = 0 p 2 I = x 0 x 1 ( r ( x ) tanh ( x ) ) x 2 x + q 0 d x = x 0 x 1 x 2 r ( x ) x + q 0 d x Q ( 2 ) ( q 0 ) = 0
where for a fixed value of q 0 such that q 0 [ x 0 , x 1 ], the above becomes a system of 3 equations in p 2 , p 1 , p 0 . If we can precompute a discretization of Q ( k ) ( q 0 ) for different values of q 0 , then we may search over the combination of coefficients that approximately minimizes the norm.

Do you have a similar question?

Recalculate according to your conditions!

Ask your question.
Get an expert answer.

Let our experts help you. Answer in as fast as 15 minutes.

Didn't find what you were looking for?