[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
54.1 Introduction to interpol | ||
54.2 Definitions for interpol |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Package interpol
defines de Lagrangian, the linear and the cubic
splines methods for polynomial interpolation.
For comments, bugs or suggestions, please contact me at 'mario AT edu DOT xunta DOT es'.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Computes the polynomial interpolation by the Lagrangian method. Argument points must be either:
p:matrix([2,4],[5,6],[9,3])
,
p: [[2,4],[5,6],[9,3]]
,
p: [4,6,3]
, in which case the abscissas will be assigned automatically to 1, 2, 3, etc.
In the first two cases the pairs are ordered with respect to the first coordinate before making computations.
With the option argument it is possible to select the name for the independent variable, which is 'x
by default; to define another one, write something like varname='z
.
Examples:
(%i1) load("interpol")$ (%i2) p:[[7,2],[8,2],[1,5],[3,2],[6,7]]$ (%i3) lagrange(p); 4 3 2 73 x - 1402 x + 8957 x - 21152 x + 15624 (%o3) ------------------------------------------- 420 (%i4) f(x):=''%; 4 3 2 73 x - 1402 x + 8957 x - 21152 x + 15624 (%o4) f(x) := ------------------------------------------- 420 (%i5) /* Evaluate the polynomial at some points */ map(f,[2.3,5/7,%pi]); 919062 (%o5) [- 1.567535000000005, ------, 84035 4 3 2 73 %pi - 1402 %pi + 8957 %pi - 21152 %pi + 15624 ---------------------------------------------------] 420 (%i6) %,numer; (%o6) [- 1.567535000000005, 10.9366573451538, 2.89319655125692] (%i7) /* Plot the polynomial together with points */ plot2d([f(x),[discrete,p]],[x,0,10], [gnuplot_curve_styles, ["with lines","with points pointsize 3"]])$ (%i8) /* Change variable name */ lagrange(p, varname=w); 4 3 2 73 w - 1402 w + 8957 w - 21152 w + 15624 (%o8) ------------------------------------------- 420 |
Returns true
if number x belongs to the interval [a, b), and false
otherwise.
Computes the polynomial interpolation by the linear method. Argument points must be either:
p:matrix([2,4],[5,6],[9,3])
,
p: [[2,4],[5,6],[9,3]]
,
p: [4,6,3]
, in which case the abscissas will be assigned automatically to 1, 2, 3, etc.
In the first two cases the pairs are ordered with respect to the first coordinate before making computations.
With the option argument it is possible to select the name for the independent variable, which is 'x
by default; to define another one, write something like varname='z
.
Examples:
(%i1) load("interpol")$ (%i2) p: matrix([7,2],[8,3],[1,5],[3,2],[6,7])$ (%i3) linearinterpol(p); (%o3) - ((9 x - 39) charfun2(x, minf, 3) + (30 - 6 x) charfun2(x, 7, inf) + (30 x - 222) charfun2(x, 6, 7) + (18 - 10 x) charfun2(x, 3, 6))/6 (%i4) f(x):=''%; (%o4) f(x) := - ((9 x - 39) charfun2(x, minf, 3) + (30 - 6 x) charfun2(x, 7, inf) + (30 x - 222) charfun2(x, 6, 7) + (18 - 10 x) charfun2(x, 3, 6))/6 (%i5) /* Evaluate the polynomial at some points */ map(f,[7.3,25/7,%pi]); 62 18 - 10 %pi (%o5) [2.3, --, - -----------] 21 6 (%i6) %,numer; (%o6) [2.3, 2.952380952380953, 2.235987755982988] (%i7) /* Plot the polynomial together with points */ plot2d(['(f(x)),[discrete,args(p)]],[x,-5,20], [gnuplot_curve_styles, ["with lines","with points pointsize 3"]])$ (%i8) /* Change variable name */ linearinterpol(p, varname='s); (%o8) - ((9 s - 39) charfun2(s, minf, 3) + (30 - 6 s) charfun2(s, 7, inf) + (30 s - 222) charfun2(s, 6, 7) + (18 - 10 s) charfun2(s, 3, 6))/6 |
Computes the polynomial interpolation by the cubic splines method. Argument points must be either:
p:matrix([2,4],[5,6],[9,3])
,
p: [[2,4],[5,6],[9,3]]
,
p: [4,6,3]
, in which case the abscissas will be assigned automatically to 1, 2, 3, etc.
In the first two cases the pairs are ordered with respect to the first coordinate before making computations.
There are three options to fit specific needs:
'd1
, default 'unknown
, is the first derivative at x_1; if it is 'unknown
, the second derivative at x_1 is made equal to 0 (natural cubic spline); if it is equal to a number, the second derivative is calculated based on this number.
'dn
, default 'unknown
, is the first derivative at x_n; if it is 'unknown
, the second derivative at x_n is made equal to 0 (natural cubic spline); if it is equal to a number, the second derivative is calculated based on this number.
'varname
, default 'x
, is the name of the independent variable.
Examples:
(%i1) load("interpol")$ (%i2) p:[[7,2],[8,2],[1,5],[3,2],[6,7]]$ (%i3) /* Unknown first derivatives at the extremes is equivalent to natural cubic splines */ cspline(p); 3 2 (%o3) ((3477 x - 10431 x - 18273 x + 74547) 3 2 charfun2(x, minf, 3) + (- 15522 x + 372528 x - 2964702 x + 7842816) charfun2(x, 7, inf) 3 2 + (28290 x - 547524 x + 3475662 x - 7184700) 3 2 charfun2(x, 6, 7) + (- 6574 x + 80028 x - 289650 x + 345924) charfun2(x, 3, 6))/9864 (%i4) f(x):=''%$ (%i5) /* Some evaluations */ map(f,[2.3,5/7,%pi]), numer; (%o5) [1.991460766423358, 5.823200187269904, 2.227405312429501] (%i6) /* Plotting interpolating function */ plot2d(['(f(x)),[discrete,p]],[x,0,10], [gnuplot_curve_styles, ["with lines","with points pointsize 3"]])$ (%i7) /* New call, but giving values at the derivatives */ cspline(p,d1=0,dn=0); 3 2 (%o7) ((17541 x - 102933 x + 153243 x + 33669) 3 2 charfun2(x, minf, 3) + (- 55692 x + 1280916 x - 9801792 x + 24990624) charfun2(x, 7, inf) 3 2 + (65556 x - 1265292 x + 8021664 x - 16597440) 3 2 charfun2(x, 6, 7) + (- 15580 x + 195156 x - 741024 x + 927936) charfun2(x, 3, 6))/20304 (%i8) /* Defining new interpolating function */ g(x):=''%$ (%i9) /* Plotting both functions together */ plot2d(['(f(x)),'(g(x)),[discrete,p]],[x,0,10], [gnuplot_curve_styles, ["with lines","with lines","with points pointsize 3"]])$ |
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated by root on October, 18 2006 using texi2html 1.76.