Function approximation Copyright © 2004-2008 DigiArea Group . All rights reserved. Description: This worksheet illustrates LdeApprox package capability of doing polynomial approximation of a given function. This method can be used if one knows an LDE which the function satisfies. First of all we load LdeApprox package and define a function to approximate and corresponding LDE. Then we use ApproxSol procedure to find 3-rd degree polynomial approximation for the LDE solution on interval x=[-h,h]. Finally we compare the function and corresponding polynomial approximation using Maple procedure plot3d . It should be pointed out that this method of approximation can be used even if the corresponding LDE has non polynomial coefficients. In this case one can use the package procedure ToRatCoeffs first to get new LDE with polynomial coefficients and then apply the method (see example with non polynomial coefficients). This loads the package. restart: with(LdeApprox): Examples: Let us try to find polynomial approximation of simple function: fun:=y(x)=exp(-n*x); 
It is obvious that the function satisfies the following initial value problem: ivp:={diff(y(x),x)+n*y(x)=0,y(0)=1}; 
Finding 3-rd degree polynomial approximation of the IVP solution on interval [-h, h]. apr:=ApproxSol(ivp, y(x), x=-h..h,3); 
Comparing exact and approximate results for h = 1 and n = 1/4 plot(subs({h=1,n=1/4},subs(fun,y(x))-subs(apr,y(x))),x=-1..1); ![[Maple Plot]](prod/LdeApproxMaple/examples/images/func7.gif)
Comparing exact and approximate results for h = 1/2 and n = -3..3 using Maple function plot3d plot3d(subs({h=1/2},subs(fun,y(x))-subs(apr,y(x))),n=-3..3,x=-1/2..1/2,axes=boxed); ![[Maple Plot]](prod/LdeApproxMaple/examples/images/func8.gif)
Comparing exact and approximate results for n = 1/2 and h = -2..2 using Maple function plot3d . plot3d(subs({n=1/2},subs(fun,y(x))-subs(apr,y(x))),x=-h..h,h=-2..2,axes=boxed); ![[Maple Plot]](prod/LdeApproxMaple/examples/images/func9.gif)
Not bad for 3-rd degree polynomial approximation, isn't it? |