Awefully confused about how to write interpolation routines
Subject: Awefully confused about how to write interpolation routines
From: Mario Rodriguez
Date: Mon, 19 Dec 2005 00:41:25 +0100
Hi Daniel,
This is not an answer to your question, but an idea for a linear
interpolating function. It's only a quick solution and it should be
enhanced (for example, ordering pairs with respect to the first
coordinate)
-------------------- begin Maxima session ------------------------
(%i1) charac(z,l1,l2):=
if l1 <= z and z < l2
then 1
else 0$
(%i2) linear_interpol(data):=block([n:length(data),s:0],
for i:2 thru n do
s: s + funmake('charac,['x,data[i-1][1],data[i][1]]) *
( data[i][2] + (data[i][2]-data[i-1][2]) *
('x-data[i][1]) /
(data[i][1]-data[i-1][1]) ),
ratsimp(s) )$
(%i3) linear_interpol([1,3],[3,6],[8,1],[9,3]);
(%o3) ((4 x - 30) charac(x, 8, 9) + (18 - 2 x) charac(x, 3, 8)
+ (3 x + 3) charac(x,
1, 3))/2
(%i4) f(x):=''%$
(%i5) f(13/5);
27
(%o5) --
5
(%i6) plot2d('(f(x)),[x,1,9])$
-------------------- end Maxima session ------------------------
Hope this helps
--
Mario Rodriguez Riotorto
www.biomates.net