From: Mario R. R. <rio...@us...> - 2005-10-02 21:31:08
|
Update of /cvsroot/maxima/maxima/share/numeric In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13711/numeric Added Files: interpol.mac Log Message: Commiting Lagrange interpolation --- NEW FILE: interpol.mac --- /* COPYRIGHT NOTICE Copyright (C) 2005 Mario Rodriguez Riotorto This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details at http://www.gnu.org/copyleft/gpl.html */ /* INTRODUCTION This package defines de Lagrangian method for polynomial interpolation. Code tested with Maxima 5.9.2 For questions, suggestions, bugs and the like, feel free to contact me at mario @@@ edu DOT xunta DOT es www.biomates.net 2005, october: first release */ /* Computes the polynomial interpolation by the Lagrangian method. The */ /* argument must be either: */ /* a) a two column matrix, p:matrix([2,4],[5,6],[9,3]) */ /* b) a list of pairs, p: [[2,4],[5,6],[9,3]] */ /* c) a list of numbers, p: [4,6,3], in which case the abscissas will be */ /* assigned automatically to 1, 2, 3, etc. */ /* Sample session: */ /* p:[[1,0],[2,1],[3,4],[4,9],[5,16],[6,25],[7,36]]$ */ /* lagrange(p); */ /* f(x):=''%; */ /* f(x),x=[2.3,5/7,%pi]; */ /* %,numer; */ /* plot2d([f(x),[discrete,p]],[x,0,10], */ /* [gnuplot_curve_styles,["with lines","with points pointsize 3"]])$ */ lagrange(tab) := block([n:length(tab),sum:0,prod], if n<2 then error("Too few sample points"), if not listp(tab[1]) then tab: makelist([i,tab[i]],i,1,n), for i:1 thru n do( prod: 1, for k:1 thru n do if k#i then prod: prod * ('x-tab[k][1]) / (tab[i][1]-tab[k][1]), sum: sum + prod * tab[i][2] ), ratsimp(sum) )$ |