help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Table lookup & interpolation


From: Ted Harding
Subject: RE: Table lookup & interpolation
Date: Wed, 19 Mar 2003 07:59:14 -0000 (GMT)

First, for interpolation I would not use your "switch" code for
table lookup; far too clumsy. Store the "table" as a matrix
whose rows are corresponding values of h and p (or as two
vectors x and p).

For this case, log(p(h)) is quite close to a linear function of h
(there is slight curvature). Possibly, linear interpolation of
log(p) between points may be adequate. If not, quadratic interpolation
using three consecutive points almost certainly is adequate.
The following compares p(h) with the result of using such linear
interpolation between (h-1000) and (h+1000), obtained by the
octave command

c=[];
for i=2:30
phat=exp((log(p(i-1))+log(p(i+1)))/2);
c=[c;[p(i) phat]];
endfor;c
    p(h)   phat(h)
  2040.90  2040.60
  1967.70  1967.48
  1896.70  1896.41
  1827.70  1827.49
  1760.80  1760.62
  1696.00  1695.70
  1633.00  1632.77
  1571.90  1571.80
  1512.90  1512.53
  1455.40  1455.25
  1399.80  1399.58
  1345.90  1345.70
  1293.70  1293.53
  1243.20  1243.01
  1194.30  1194.13
  1147.00  1146.75
  1101.10  1101.03
  1056.90  1056.65
  1014.00  1013.87
   972.60   972.40
   932.50   932.37
   893.80   893.64
   856.40   856.26
   820.30   820.08
   785.30   785.25
   751.70   751.52
   719.20   719.09
   687.90   687.71
   657.60   657.53

Clearly these are pretty close, and I'm sure a quadratic in log(p)
would be very close indeed.

I hope this helps!
Ted.

On 19-Mar-03 Luke Scharf wrote:
> I've implemented a function as a table lookup.  It would be nice if it
> could interpolate between the values as well.  Any ideas?
> 
> Here is what I'm using now.  It works -- except no interpolation:
> ------------------- Begin Code Snippet -------------------
> % p(h) - pressure as a function of altitude
> function a = p_helper(h)
>       switch (h(:))
>               case (0)        a = 2116.2;
>               case (1000)     a = 2040.9;
>               case (2000)     a = 1967.7;
>               case (3000)     a = 1896.7;
>               case (4000)     a = 1827.7;
>               case (5000)     a = 1760.8;
>               case (6000)     a = 1696.0;
>               case (7000)     a = 1633.0;
>               case (8000)     a = 1571.9;
>               case (9000)     a = 1512.9;
>               case (10000)    a = 1455.4;
>               case (11000)    a = 1399.8;
>               case (12000)    a = 1345.9;
>               case (13000)    a = 1293.7;
>               case (14000)    a = 1243.2;
>               case (15000)    a = 1194.3;
>               case (16000)    a = 1147.0;
>               case (17000)    a = 1101.1;
>               case (18000)    a = 1056.9;
>               case (19000)    a = 1014.0;
>               case (20000)    a = 972.6;
>               case (21000)    a = 932.5;
>               case (22000)    a = 893.8;
>               case (23000)    a = 856.4;
>               case (24000)    a = 820.3;
>               case (25000)    a = 785.3;
>               case (26000)    a = 751.7;
>               case (27000)    a = 719.2;
>               case (28000)    a = 687.9;
>               case (29000)    a = 657.6;
>               case (30000)    a = 628.5;
>               otherwise       a = -1;
>       endswitch
> endfunction
> function a = p(h)
>       count = 1;
>       for i(:) = h
>               a(count) = p_helper(i);
>               count = count+1;
>       endfor
> endfunction
> ------------------- End Code Snippet -------------------
> 
> 
> If there a Right Way to do this?
> 
> 
> Thanks in advance,
> -Luke
> 
> 
> 
> -------------------------------------------------------------
> Octave is freely available under the terms of the GNU GPL.
> 
> Octave's home on the web:  http://www.octave.org
> How to fund new projects:  http://www.octave.org/funding.html
> Subscription information:  http://www.octave.org/archive.html
> -------------------------------------------------------------

--------------------------------------------------------------------
E-Mail: (Ted Harding) <address@hidden>
Fax-to-email: +44 (0)870 167 1972
Date: 19-Mar-03                                       Time: 07:59:14
------------------------------ XFMail ------------------------------



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]