[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

53. interpol


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

53.1 Introducción a interpol

El paquete interpol desarrolla los métodos de interpolación polinómica de Lagrange, lineal y de splines cúbicos.

Para comentarios, fallos o sugerencias, contactar con 'mario ARROBA edu PUNTO xunta PUNTO es'.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

53.2 Definiciones para interpol

Función: lagrange (points)
Función: lagrange (points, option)

Calcula el polinomio de interpolación por el método de Lagrange. El argumento points debe ser:

En los dos primeros casos los pares se ordenan con respecto a la primera coordenada antes de proceder a los cálculos.

Mediante el argumento option es posible seleccionar el nombre de la variable independiente, que por defecto es 'x; para definir otra, escríbase algo como varname='z.

Ejemplos:

 
(%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
Función: charfun2 (x, a, b)

Devuelve true si el número x pertenece al intervalo [a, b), y false en caso contrario.

Función: linearinterpol (points)
Función: linearinterpol (points, option)

Calcula rectas de interpolación. El argumento points debe ser:

En los dos primeros casos los pares se ordenan con respecto a la primera coordenada antes de proceder a los cálculos.

Mediante el argumento option es posible seleccionar el nombre de la variable independiente, que por defecto es 'x; para definir otra, escríbase algo como varname='z.

Ejemplos:

 
(%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
Función: cspline (points)
Función: cspline (points, option1, option2, ...)

Calcula el polinomio de interpolación por el método de los splines cúbicos. El argumento points debe ser:

En los dos primeros casos los pares se ordenan con respecto a la primera coordenada antes de proceder a los cálculos.

Esta función dispone de tres opciones para acomodarse a necesidades concretas:

Ejemplos:

 
(%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 noviembre, 10 2006 using texi2html 1.76.