Next Article in Journal
Time Needed to Control an Epidemic with Restricted Resources in SIR Model with Short-Term Controlled Population: A Fixed Point Method for a Free Isoperimetric Optimal Control Problem
Previous Article in Journal
Application of Approximate Analytical Technique Using the Homotopy Perturbation Method to Study the Inclination Effect on the Thermal Behavior of Porous Fin Heat Sink
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

A Computational Method with MAPLE for a Piecewise Polynomial Approximation to the Trigonometric Functions

Department of Mathematics, College of Natural Sciences, Cantho University, 3/2 Street, Cantho City, Vietnam
Math. Comput. Appl. 2018, 23(4), 63; https://doi.org/10.3390/mca23040063
Submission received: 13 August 2018 / Revised: 4 October 2018 / Accepted: 16 October 2018 / Published: 17 October 2018

Abstract

:
A complete MAPLE procedure is designed to effectively implement an algorithm for approximating trigonometric functions. The algorithm gives a piecewise polynomial approximation on an arbitrary interval, presenting a special partition that we can get its parts, subintervals with ending points of finite rational numbers, together with corresponding approximate polynomials. The procedure takes a sequence of pairs of interval–polynomial as its output that we can easily exploit in some useful ways. Examples on calculating approximate values of the sine function with arbitrary accuracy for both rational and irrational arguments as well as drawing the graph of the piecewise approximate functions are presented. Moreover, from the approximate integration on [ a , b ] with integrands of the form x m sin x , another MAPLE procedure is proposed to find the desired polynomial estimates in norm for the best L 2 -approximation of the sine function in the vector space P of polynomials of degree at most , a subspace of L 2 ( a , b ) .

1. Introduction

There are two aspects of implementation of an algorithm. One is the illustration for the validity of the algorithm, and the other for the efficient exploitation of its steps thanks to the choice of suitable tools.
Remez’s minimax algorithm is well established (see Section 3.5 in [1]), but all the steps to proceed it contain the two main obstacles when being performed in practice:
  • solving a nonlinear equation and a system of linear equations; and
  • using the cosine function to compute the initial set of points.
As a warning to experienced users, they should have close control of the evaluation error at almost every calculation for the above steps. Therefore, it could be difficult to effectively implement this algorithm for approximating the trigonometric functions themselves.
Here, we choose Algorithm 2 in [2] to be implemented with MAPLE (or any of Computer Algebra Systems (CAS), if possible), because it has the great advantage: only using arithmetic calculations on finite rational numbers and comparisons. The choice of MAPLE is due to its powerfulness of symbolic computation and its ability to display exact number of significant digits for the obtained numerical results. The description of Algorithm 2 is clear, but examples on numerical integration and graphical plots in [2] seem to be as of the first kind of implementation as mentioned above. Therefore, we come back to the article [2] with aspiration to provide the beginners or occasional users with a complete MAPLE procedure, the output of which being easy and convenient to exploit when implementing Algorithm 2.
From [2], we have that the function sin x is piecewise approximated on an interval [ a , b ] by the polynomials A i ( x ) on the subintervals [ α i , α i + 1 ] , i = 0 , , n , such that [ a , b ] = [ a , α 1 ] [ α 1 , α 2 ] [ α n , b ] , where α 0 = a and α n + 1 = b and
A i ( x ) = ( 1 ) ( k i 1 ) / 2 m = 0 n / 2 ( 1 ) m ( 2 m ) ! ( x k i p i ) 2 m ,
or
A i ( x ) = ( 1 ) k i / 2 m = 0 ( n 1 ) / 2 ( 1 ) m ( 2 m + 1 ) ! ( x k i p i ) 2 m + 1 , i = 0 , , n .
These approximations all have the accuracy of 1 / 10 r in absolute value for a given arbitrary positive integer r. The main purpose of Algorithm 2 is to give the pairs of [ α i , α i + 1 ] , A i ( x ) , i = 0 , , n , and, as a convention, the notations of this output is used in the next sections.
The paper is organized as follows. In Section 2, we construct a complete MAPLE procedure by blocks of commands so that we can modify them easily. These blocks whose purpose is clearly explained may be useful to design other procedures. Section 3 is for exploitation of the obtained results from the output of the procedure. Section 3 is the detailed discussion on how to find a desired estimate p for the best L 2 -approximation p best of the sine function in the vector space P . In particular, it is possible to make a complete MAPLE procedure to find p’s with different values of from the existing materials, and we let the reader do it with his or her close control of evaluation error for the steps containing norms of vectors. Moreover, the crucial components of a procedure that computes approximate values of integration with integrands of the form x m sin x ( m N ) are also provided. Section 4 is the conclusion.

2. Implementation by MAPLE Procedures

We list here the MAPLE commands that appear in our procedures. They are all very important and frequently used in MAPLE programming: add, coeff, Digits, ERROR, evalf, floor, for, irem, int, nops, op, piecewise, RETURN, seq, sort, and while. A declaration to create a function, e.g., f, such as f:=x->F(x) or f:=unapply(F(x),x), where F(x) is an expression in x, is a very useful and convenient tool in MAPLE procedures for doing calculations. In addition, the conditional structure ifthen is indispensable in branch programming, whereas the type list is a flexible ordered arrangement of operands (or things and elements). See [3,4] and MAPLE help pages in each session to know more details about meaning, syntax and usage of these commands, structures and types.
In the following, we consider in succession the steps to perform Algorithm 2 in [2] with their content and corresponding MAPLE codes. However, we modify some steps in Algorithm 2 to get the extraction results conveniently from its output. Firstly, we recall the two blocks of commands (inside steps) for getting the degree n of the approximate polynomial P n c ( x ) of the function sin x (Block 1), which satisfies the accuracy of 1 / 10 r , and for finding the approximate values of π / 2 , which appear in P n c ( x ) .
Block 1
n:=0: d:=1:
while (d>0) do
n:=n+1:
d:=(0.8)^(n+1)*10^(r+1)-(n+1)!;
end do:
Block 2 is nothing but the full content of FindPoint, a procedure to determine nodes of the form k p , where k Z and p is an approximate value of π / 2 (see [2]). These nodes are ending points of subintervals in the partition of an arbitrary interval [ a , b ] . The output of FindPoint from its argument y also gives the approximate polynomial F. Moreover, we have them all together, k, p and F from a list of three components; that is, we may write FindPoint ( y ) = [ k,p’,P] with p p = π / 2 , | sin x P ( x ) | < 1 / 10 r for all x [ k p p / 2 , k p + p / 2 ] and | y k p | < 0.8 .
Block 2
m:=r+2:
while ((b+3.2)*10^(r+3)-10^m>0) do
m:=m+1:
end do:
Digits:=m+4:
q:=evalf[m+3](Pi/2):
T:=x/q-floor(x/q):
if (T=0.5) then
k0:=floor(x/q):
else
while (2.4*10^m*min(T,0.5-T)-abs(x)<0) and
  (2.4*10^m*min(1-T,T-0.5)-abs(x)<0) do
m:=m+1: Digits:=m+4:
q:=evalf[m+3](Pi/2):
T:=x/q-floor(x/q):
end do:
end if:
if (0.5<T) then
k0:=floor(x/q)+1:
else
k0:=floor(x/q):
end if:
if (irem(k0-1,2)=0) then
F:=unapply((-1)^((k0-1)/2)*add((-1)^s*(t-k0*q)^(2*s)/((2*s)!),
    s=0..floor(n/2)),t):
else
F:=unapply((-1)^(k0/2)*add((-1)^s*(t-k0*q)^(2*s+1)/((2*s+1)!),
    s=0..floor((n-1)/2)),t):
end if:
[k0,q,F];
Next, Block 3 that may be the most important one is designed to find approximate polynomials A j ( x ) , corresponding to intervals [ α j 1 , α j ] , where α j , j = 1 , , i , are the nodes mentioned above. This block gives a so-called spreading technique that takes nodes together with the polynomials A j ( x ) , by using Block 2 successively, as clearly described in [2]. We choose the output of Block 3 as a function of a finite sequence of lists given in the form of
H : = x [ α 0 , α 1 ] , A 0 ( x ) , [ α 1 , α 2 ] , A 1 ( x ) , , [ α i 1 , α i ] , A i 1 ( x ) .
This output has the advantages of a function itself or a sequence of terms, because we can take its values H ( x ) and H ( x ) , or its components (or operands) h j ( x ) = [ α j 1 , α j ] , A j 1 ( x ) as we want.
We design a MAPLE procedure named ApproxFunct to give the approximate function P for the sine function on an interval [ a , b ] for a 0 . In the cases of 0 a < b 0.8 and 0 a < 0.8 < b , we may set P = G on [ a , b ] and P = G on [ a , 0.8 ] , respectively, where
G ( x ) = m = 0 ( n 1 ) / 2 ( 1 ) m ( 2 m + 1 ) ! x 2 m + 1
and n is determined by Block 1. Before giving the MAPLE codes of Block 3 chosen as the full content of TempApproxFunct, the procedure to give the approximation to the sine function on [ a , b ] only for a 0.8 , we recall here (from [2]) the important remark: if α , β [ a , b ] are numbers such that
FindPoint ( α ) [ 1 ] = FindPoint ( β ) [ 1 ] = k
with p’ = FindPoint( α )[2], p” = FindPoint( β )[2], then we have |αkp”| < 0.8 and |βkp’| < 0.8.
Block 3
n0:=FindPoint(b)[1]:
p0:=FindPoint(b)[2]:
B0:=FindPoint(b)[3]:
i:=0:
k[i]:=FindPoint(a)[1]:
p[i]:=FindPoint(a)[2]:
A[i]:=FindPoint(a)[3]:
u:=k[i]:
if n0<=u then
H:=x->[[a,b],A[0](x)]:
RETURN(H);
end if:
while u<n0 do
i:=i+1:
k[i]:=FindPoint(k[i-1]*p[i-1]+p[i-1])[1]:
p[i]:=FindPoint(k[i-1]*p[i-1]+p[i-1])[2]:
A[i]:=FindPoint(k[i-1]*p[i-1]+p[i-1])[3]:
u:=k[i]:
end do:
if i=1 then
  if b<=k[0]*p[0]+p[0]/2 then
H:=x->[[a,b],A[0](x)]:
RETURN(H);
  elif b<=k[0]*p[0]+p[0] then
H:=x->([[a,k[0]*p[0]+p[0]/2],A[0](x)],[[k[0]*p[0]+p[0]/2,b],A[1](x)]):
  RETURN(H);
  else
H:=x->([[a,k[0]*p[0]+p[0]/2],A[0](x)],[[k[0]*p[0]+p[0]/2,k[0]*p[0]+p[0]],
A[1](x)],[[k[0]*p[0]+p[0],b],B0(x)]):
  RETURN(H);
  end if:
elif i=2 then
  if b<=k[1]*p[1]+p[1]/2 then
H:=x->([[a,k[0]*p[0]+p[0]/2],A[0](x)],[[k[0]*p[0]+p[0]/2,b],A[1](x)]):
  RETURN(H);
  elif b<=k[1]*p[1]+p[1] then
H:=x->([[a,k[0]*p[0]+p[0]/2],A[0](x)],[[k[0]*p[0]+p[0]/2,k[1]*p[1]+p[1]/2],
A[1](x)],[[k[1]*p[1]+p[1]/2,b],A[2](x)]):
  RETURN(H);
  else
H:=x->([[a,k[0]*p[0]+p[0]/2],A[0](x)],[[k[0]*p[0]+p[0]/2,k[1]*p[1]+p[1]/2],
A[1](x)],[[k[1]*p[1]+p[1]/2,k[1]*p[1]+p[1]],A[2](x)],[[k[1]*p[1]+p[1],b],B0(x)]):
  RETURN(H);
  end if:
else
  if b<=k[i-1]*p[i-1]+p[i-1]/2 then
H:=x->([[a,k[0]*p[0]+p[0]/2],A[0](x)],seq([[k[m-1]*p[m-1]+p[m-1]/2,
k[m]*p[m]+p[m]/2],A[m](x)],m=1..i-2),[[k[i-2]*p[i-2]+p[i-2]/2,b],A[i-1](x)]):
  RETURN(H);
  elif b<=k[i-1]*p[i-1]+p[i-1] then
H:=x->([[a,k[0]*p[0]+p[0]/2],A[0](x)],seq([[k[m-1]*p[m-1]+p[m-1]/2,
k[m]*p[m]+p[m]/2],A[m](x)],m=1..i-1),[[k[i-1]*p[i-1]+p[i-1]/2,b],A[i](x)]):
  RETURN(H);
  else
H:=x->([[a,k[0]*p[0]+p[0]/2],A[0](x)],seq([[k[m-1]*p[m-1]+p[m-1]/2,
k[m]*p[m]+p[m]/2],A[m](x)],m=1..i-1),[[k[i-1]*p[i-1]+p[i-1]/2,k[i]*p[i-1]],
A[i](x)],[[k[i]*p[i-1],b],B0(x)]):
  RETURN(H);
  end if:
end if:
Note that TempApproxFunct takes three arguments in order as a, b and r. Next, we combine Block 1 and Block 3 with some conditional commands to form Block 4, which is the content of the ApproxFunct.
Block 4
G:=unapply(add((-1)^s*t^(2*s+1)/((2*s+1)!),s=0..floor((n-1)/2)),t):
if (a<0) then ERROR(‘1st argument must be nonegative’);
elif (a<0.8) then
  if (b<=0.8) then
  [[a,b],G];
  else
  ([[a,0.8],G],TempApproxFunct(0.8,b,r));
  end if:
else
TempApproxFunct(a,b,r);
end if:
Now, we may call ApproxFunct(a,b,r) to fully access all subintervals together with approximate polynomials for the accuracy of 1 / 10 r on an interval [ a , b ] , a 0 . In particular, if we want to extract the jth interval and its corresponding approximate polynomial, use the calling sequence ApproxFunct(a,b,r)(x)[j], where j is chosen from the output ApproxFunct(a,b,r)(x).
Finally, from the above analysis, we obtain the desired procedure named PiecewiseFunct (see the supplementary material accompanying this paper for MAPLE codes), which gives a special partition of an arbitrary interval [ a , b ] into subintervals [ α j 1 , α j ] together with corresponding approximate polynomials A j ( x ) , where
| sin x A j ( x ) | < 1 10 r for all x [ α j 1 , α j ] , j = 1 , , N ,
with N = nops ( [ PiecewiseFunct ( a , b , r ) ] ) . Here, there is a warning that, in MAPLE, if A:=a,b,c,d or A:=(a,b,c,d), we cannot determine nops(A); however, we can if A:=[a,b,c,d], so nops ( A ) = 4 . To all three settings for A, we can select ordered elements of A, namely A [ 3 ] = c , for example.
Thus, a complete MAPLE procedure to perform Algorithm 2 in [2] is suggested to be
The PiecewiseFunct procedure
PiecewiseFunct:=proc(a::realcons,b::realcons,r::posint)
local ApproxFunct,j,n,d,G,num,funct,intrv;
ApproxFunct:=proc(a::realcons,b::realcons,r::posint)
local TempApproxFunct,n,d,G;option remember;
TempApproxFunct:=proc(a::realcons,b::realcons,r::posint)
local i,p0,n0,B0,u,p,k,A,H,FindPoint;option remember;
FindPoint:=proc(x::realcons)
local m,q,n,d,k0,F,T;option remember;
Block 1
Block 2
end proc:
Block 3
end proc:
Block 1
Block 4
end proc:
Block 1
G:=unapply(add((-1)^s*t^(2*s+1)/((2*s+1)!),s=0..floor((n-1)/2)),t):
if (0<=a) then
ApproxFunct(a,b,r)(x);
elif (-0.8<=a) then
  if (b<=0) then
  [[a,b],G(x)];
  else
  ([[a,0],G(x)],ApproxFunct(0,b,r)(x));
  end if:
else
  if (b<=0) then
  num:=nops([ApproxFunct(-b,-a,r)(-x)]):
  for j from 1 to num do
  funct[j]:=op(2,(-1)*ApproxFunct(-b,-a,r)(-x)[j]):
  intrv[j]:=sort(op(1,(-1)*ApproxFunct(-b,-a,r)(-x)[j])):
  end do:
  seq([intrv[num+1-i],funct[num+1-i]],i=1..num);
  else
  num:=nops([ApproxFunct(0,-a,r)(-x)]):
  for j from 1 to num do
  funct[j]:=op(2,(-1)*ApproxFunct(0,-a,r)(-x)[j]):
  intrv[j]:=sort(op(1,(-1)*ApproxFunct(0,-a,r)(-x)[j])):
  end do:
  (seq([intrv[num+1-i],funct[num+1-i]],i=1..num),ApproxFunct(0,b,r)(x));
  end if:
end if:
end proc:
The last part of the PiecewiseFunct procedure might need to be explained in more detail. In the case a < b 0 , we make a partition first for the interval [ b , a ] ; then, from the result of the partition, we take a sample of the form [ β j 1 , β j ] , B j ( x ) and convert it into its symmetric part in the partition of [ a , b ] : [ β j , β j 1 ] , B j ( x ) . Such a sample in MAPLE language is given by the declaration: [intrv[j],funct[j]], where
intrv [ j ] : = sort ( op ( 1 , ( 1 ) ApproxFunct ( b , a , r ) ( x ) [ j ] ) ) , funct [ j ] : = op ( 2 , ( 1 ) ApproxFunct ( b , a , r ) ( x ) [ j ] ) .
Because the converted intervals should be arranged in the correct order on the real axis, we use the calling sequence seq([intrv[num+1-i],funct[num+1-i]],i=1..num).
In fact, PiecewiseFunct contains a technique that indirectly solves a difficult problem “How to reduce values of arguments when doing calculations with the trigonometric functions”. There was a great attempt to solve the problem and perhaps [1] would be one of the best reference books on this fact. However, this technique is only a suitable remedy for applying Taylor’s Theorem, which has not been considered a good way in approximation theory.
PiecewiseFunct can be also used to give pointwise approximate values of the sine function, so we do not need to recall here Algorithm 1 (see [2]). A hint: Combine Block 1, Block 2 and the illustrated MAPLE codes for the distinction between “r-th decimal digit” and “r significant digits” on [2] to make a procedure, e.g., Sine, to implement Algorithm 1.

3. Exploitation of the Output of the PiecewiseFunct Procedure

Firstly, we save the result from performing PiecewiseFunct in a variable chosen as a list of lists A:=[PiecewiseFunct(a,b,r)], then put num:=nops(A). Now, we number the ending points of subintervals and corresponding approximate polynomials, for instance, by a for-loop:
for i from 1 to num do   a [ i ] : = op ( 1 , op ( 1 , A [ i ] ) ) :   b [ i ] : = op ( 2 , op ( 1 , A [ i ] ) ) :   F [ i ] : = op ( 2 , A [ i ] ) : end do :
For a given number α [ a , b ] , we can choose the index i such that the interval [ a [ i ] , b [ i ] ] contains α , hence we put g : = unapply ( F [ i ] , x ) . Note that F[i] is still an expression in x as default, not a function; besides, we cannot set g : = x > F [ i ] because x here and x in F[i] are not the same by MAPLE’s rule. Then, sin α g ( α ) with the accuracy of 1 / 10 r . In MAPLE, we can use the command piecewise for a sequence of conditional settings to get the piecewise polynomial approximation to the sine function on [ a , b ] by putting
f : = x > piecewise ( seq ( [ a [ j ] < = x   and   x < = b [ j ] , F [ j ] ] [ ] , j = 1 . . num ) , NULL ) :
Now, we have sin x f ( x ) for all x [ a , b ] with the accuracy of 1 / 10 r .
In the following, we take examples on approximating values of the sine function at rational and irrational arguments and getting the graph of approximate functions on an arbitrary intervals with various accuracy. Moreover, the approximation of integration on [ a , b ] with integrands of the form x m sin x ( m N ) is considered in both theoretical and practical aspects.
To find the approximate value of sin ( 123.45 ) with the accuracy of 1 / 10 20 , we put A : = [ PiecewiseFunct ( 123,124,20 ) ] . Then, nops ( A ) = 2 and the interval [ 123 , 124 ] is partitioned into the subintervals [ 123 , 123.3075117 ] and [ 123.3075117 , 124 ] . Thus, we take f : = unapply ( op ( 2 , A [ 2 ] ) , x ) and obtain
f ( x ) = 1 + ( x x 0 ) 2 2 ( x x 0 ) 4 24 + ( x x 0 ) 6 720 ( x x 0 ) 8 40320 + ( x x 0 ) 10 3628800 ( x x 0 ) 12 479001600 + ( x x 0 ) 14 87178291200 ( x x 0 ) 16 20922789888000 + ( x x 0 ) 18 6402373705728000 ( x x 0 ) 20 2432902008176640000 ,
where x 0 = 123.092909816796832919274413636 . Hence, we have the desired approximation
sin ( 123.45 ) evalf [ 20 ] ( f ( 123.45 ) ) = 0.80035463532671180916 .
Now, with an irrational number x, how do we approximate the value of sin x with the accuracy of 1 / 10 r ? In principle, we can find a rational number x such that | x x | < 1 / 10 r + 1 and use the PiecewiseFunct procedure to determine a polynomial P that satisfies | sin ( x ) P ( x ) | < 1 / 10 r + 1 . Then, we have the estimate | sin x P ( x ) | < 1 / 10 r . For example, we approximate the value of sin ( 3 ) with the accuracy of 1 / 10 50 by first taking
3 x = 1.732050807568877293527446341505872366942805253810381 .
Since nops ( A ) = 1 , with A : = [ PiecewiseFunct ( 1.73,2,51 ) ] , we set f : = unapply ( op ( 2 , A [ 1 ] ) , x ) . Then, we have the needed estimate
sin ( 3 ) evalf [ 51 ] ( f ( x ) ) = 0.987026644990353783993324392439670388957092614144764 .
There are many algorithms in the literature to find rational approximations to an irrational number with the desired accuracy, mostly using continued fractions. The theoretical basis of this classic problem can be found in the two great books [5] and [6]. CAS of course have their built-in commands to compute such approximations. Here, we may take x by the calling sequence evalf[51](sqrt(3)).
Besides, from Equation (1) with the declaration in Equation (2), we derive the graph of piecewise polynomial approximation to the sine function by the command plot ( f ( x ) , x = a . . b , numpoints = 500 ) . We choose the large values r = 150 and r = 500 for the intervals [ 200 , 50 ] and [ 100 , 600 ] , respectively. Let us try the case r = 500 to see the display of 448 pairs of interval–polynomial with the accuracy of 1 / 10 500 . The corresponding graphs are depicted in Figure 1.
We may also exploit PiecewiseFunct from the other side of our approximation. We have used Taylor polynomials with larger degrees when higher accuracy is required thus far. If we want to confine approximate polynomials to a fixed degree, we might relate this determination to the vector space P , a subspace of L 2 ( a , b ) . We know that in P there is the best polynomial approximation p best of the sine function in L 2 -norm · = · , · 1 / 2 of L 2 ( a , b ) , which is endowed with the inner product
φ , ψ = a b φ ( x ) ψ ( x ) d x .
Now, we use the Gram–Schmidt procedure to find an orthonormal basis { p 0 , p 1 , , p } for P from the basis { 1 , x , x 2 , , x } , according to the recursion
p 0 : = 1 / 1 = 1 / b a , q k : = x k i = 0 k 1 x k , p i p i , p k : = q k / q k , k = 1 , , .
Once the orthonormal basis has been found, we obtain
p best = sin , p 0 p 0 + sin , p 1 p 1 + + sin , p p = k = 0 sin , p k p k .
To give an estimate for sin F , where F is our piecewise polynomial approximation to the sine function on [ a , b ] , we first approximate sin , p k by
sin , p k = a b p k ( x ) sin x d x F , p k = a b p k ( x ) F ( x ) d x .
These estimates have the absolute error
| sin , p k F , p k | = | sin F , p k | sin F ,
where
sin F = a b | sin x F ( x ) | 2 d x 1 / 2 b a 10 2 r 1 / 2 = b a 10 r .
Therefore, we may choose
p best c : = k = 0 F , p k p k
as an approximation of p best . Then, we have the following estimation for the error norm
p best p best c = k = 0 sin F , p k p k k = 0 | sin F , p k | ( + 1 ) b a 10 r .
Hence, we may take r = lg ( ( + 1 ) b a ) + 1 + u to obtain the estimate
p best p best c < 1 10 u .
To determine p best c with MAPLE, it would be better to write the polynomial p k in the form of p k : = s = 0 k a k s x s , hence we have
F , p k = s = 0 k a k s F , x s , with F , x s = a b x s F ( x ) d x = i = 0 n α i α i + 1 x s A i ( x ) d x .
According to the initial settings in Equation (1), the coefficients a k s and the inner products F , x s can be computed by the following commands
a k s coeff ( p [ k ] , x , s ) F , x s add ( int ( x ^ s F [ i ] , x = a [ i ] . . b [ i ] ) , i = 1 . . num )
We can make a procedure named PowerIntApprox only to compute F , x s , s = 0 , , . This procedure, which has one more argument, e.g., “deg”, for the chosen degree of p best , may take all the blocks of PiecewiseFunct, but replacing the output of Block 3, Block 4 and the last part of PiecewiseFunct with the commands recapped in the following. For the output RETURN of Block 3, we take the sum of integrals of x s A i ( x ) on [ α i , α i + 1 ] , instead of giving the sequence of [ α i , α i + 1 ] , A i ; and we do similarly for the output of Block 4. The last part of PiecewiseFunct may be replaced with the commands
if 0 < = a then evalf [ r ] ( ApproxInt ( a , b , deg , r ) ) ; elif b < = 0 then evalf [ r ] ( [ seq ( ( 1 ) ^ ( i + 1 ) ApproxInt ( b , a , deg , r ) [ i + 1 ] , i = 0 . . deg ) ] ) ; else evalf [ r ] ( [ seq ( ( 1 ) ^ ( i + 1 ) ApproxInt ( 0 , a , deg , r ) [ i + 1 ] , i = 0 . . deg ) ] + ApproxInt ( 0 , b , deg , r ) ) ; end if :
and the reason we do so can be easily recognized. Here, ApproxInt has a similar role as ApproxFunct, but is simpler to use.
Now, we have enough materials derived from Equations (3)–(6) to make a procedure for finding a desired approximation on [ a , b ] in L 2 -norm to the best approximation p best of the sine function in P with a given positive integer . The procedure takes four arguments, a, b, and u, to give p P as its output such that p p best < 1 / 10 u . As mentioned above, if we named the procedure BestApprox, hence it takes PowerIntApprox as its local variable, then it would be interesting to run BestApprox with different values of its input. However, as warned in Section 1, we should pay much attention to the cases of large values of and u to take an appropriate regulation.

4. Conclusions

There could be some more useful ways to exploit the output of PiecewiseFunct and its corollary, PowerIntApprox, as well as Sine. Although these procedures are designed only for the sine function, we can make some appropriate changes to the blocks of commands to obtain their “cosine” version. It is hoped that some application results of our procedures would supply some more improved computational tools in applied mathematics.

Supplementary Materials

The MAPLE codes of the PiecewiseFunct procedure are available at https://www.mdpi.com/2297-8747/23/4/63/s1.

Acknowledgments

The author is very grateful to Professor Henk Pijls (University of Amsterdam, the Netherlands) for his valuable advice and constant encouragement since 1998, and also wants to express his thankfulness to the Maplesoft experts for their great work on developing MAPLE, a powerful and user-friendly product.

Conflicts of Interest

The author declares no conflict of interest.

References

  1. Muller, J.M. Elementary Functions—Algorithms and Implementation, 2nd ed.; Birkhäuser Boston: New York, NY, USA, 2006. [Google Scholar]
  2. Quan, L.P.; Nhan, T.A. Applying Computer Algebra Systems in Approximating the Trigonometric Functions. Math. Comput. Appl. 2018, 23, 37. [Google Scholar] [CrossRef]
  3. Monagan, M.B.; Geddes, K.O.; Heal, K.M.; Labahn, G.; Vorkoetter, S.M.; McCarron, J.; DeMarco, P. MAPLE Introductory Programming Guide; Waterloo MAPLE Inc.: Ontario, ON, Canada, 2008. [Google Scholar]
  4. Monagan, M.B.; Geddes, K.O.; Heal, K.M.; Labahn, G.; Vorkoetter, S.M.; McCarron, J.; DeMarco, P. MAPLE Advanced Programming Guide; Waterloo MAPLE Inc.: Ontario, ON, Canada, 2008. [Google Scholar]
  5. Hardy, G.H.; Wright, E.M.; Wiles, A. An Introduction to the Theory of Numbers, 6th ed.; Heath-Brown, R., Silverman, J., Eds.; Oxford University Press: Oxford, UK, 2008. [Google Scholar]
  6. Niven, I.; Zuckerman, H.S.; Montgomery, H.L. An Introduction to the Theory of Numbers, 5th ed.; John Wiley & Sons, Inc.: New York, NY, USA, 1991. [Google Scholar]
Figure 1. The graphs of f with: r = 150 (left); and r = 500 (right).
Figure 1. The graphs of f with: r = 150 (left); and r = 500 (right).
Mca 23 00063 g001

Share and Cite

MDPI and ACS Style

Quan, L.P. A Computational Method with MAPLE for a Piecewise Polynomial Approximation to the Trigonometric Functions. Math. Comput. Appl. 2018, 23, 63. https://doi.org/10.3390/mca23040063

AMA Style

Quan LP. A Computational Method with MAPLE for a Piecewise Polynomial Approximation to the Trigonometric Functions. Mathematical and Computational Applications. 2018; 23(4):63. https://doi.org/10.3390/mca23040063

Chicago/Turabian Style

Quan, Le Phuong. 2018. "A Computational Method with MAPLE for a Piecewise Polynomial Approximation to the Trigonometric Functions" Mathematical and Computational Applications 23, no. 4: 63. https://doi.org/10.3390/mca23040063

Article Metrics

Back to TopTop