Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.ALGLIB/2.3.0/ALGLIB-2.3.0/ratinterpolation.cs @ 2806

Last change on this file since 2806 was 2806, checked in by gkronber, 14 years ago

Added plugin for new version of ALGLIB. #875 (Update ALGLIB sources)

File size: 4.1 KB
Line 
1/*************************************************************************
2Copyright (c) 2007, Sergey Bochkanov (ALGLIB project).
3
4>>> SOURCE LICENSE >>>
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation (www.fsf.org); either version 2 of the
8License, or (at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13GNU General Public License for more details.
14
15A copy of the GNU General Public License is available at
16http://www.fsf.org/licensing/licenses
17
18>>> END OF LICENSE >>>
19*************************************************************************/
20
21using System;
22
23namespace alglib
24{
25    public class ratinterpolation
26    {
27        /*************************************************************************
28        Rational barycentric interpolation without poles
29
30        The subroutine constructs the rational interpolating function without real
31        poles. It should be noted that the barycentric weights of the  interpolant
32        constructed are independent of the values of the given function.
33
34        Input parameters:
35            X   -   interpolation nodes, array[0..N-1].
36            N   -   number of nodes, N>0.
37            D   -   order of the interpolation scheme, 0 <= D <= N-1.
38
39        Output parameters:
40            W   -   array of the barycentric weights which  can  be  used  in  the
41                    BarycentricInterpolate subroutine. Array[0..N-1]
42
43        Note:
44            this algorithm always succeeds and calculates the weights  with  close
45            to machine precision.
46
47          -- ALGLIB PROJECT --
48             Copyright 17.06.2007 by Bochkanov Sergey
49        *************************************************************************/
50        public static void buildfloaterhormannrationalinterpolant(double[] x,
51            int n,
52            int d,
53            ref double[] w)
54        {
55            double s0 = 0;
56            double s = 0;
57            double v = 0;
58            int i = 0;
59            int j = 0;
60            int k = 0;
61            int[] perm = new int[0];
62            double[] wtemp = new double[0];
63            int i_ = 0;
64
65            x = (double[])x.Clone();
66
67            System.Diagnostics.Debug.Assert(n>0, "BuildRationalInterpolantWithoutPoles: N<=0!");
68            System.Diagnostics.Debug.Assert(d>=0 & d<=n, "BuildRationalInterpolantWithoutPoles: incorrect D!");
69           
70            //
71            // Prepare
72            //
73            w = new double[n-1+1];
74            s0 = 1;
75            for(k=1; k<=d; k++)
76            {
77                s0 = -s0;
78            }
79            perm = new int[n-1+1];
80            for(i=0; i<=n-1; i++)
81            {
82                perm[i] = i;
83            }
84            tsort.tagsortfasti(ref x, ref perm, n);
85           
86            //
87            // Calculate Wk
88            //
89            for(k=0; k<=n-1; k++)
90            {
91               
92                //
93                // Wk
94                //
95                s = 0;
96                for(i=Math.Max(k-d, 0); i<=Math.Min(k, n-1-d); i++)
97                {
98                    v = 1;
99                    for(j=i; j<=i+d; j++)
100                    {
101                        if( j!=k )
102                        {
103                            v = v/Math.Abs(x[k]-x[j]);
104                        }
105                    }
106                    s = s+v;
107                }
108                w[k] = s0*s;
109               
110                //
111                // Next S0
112                //
113                s0 = -s0;
114            }
115           
116            //
117            // Reorder W
118            //
119            wtemp = new double[n-1+1];
120            for(i_=0; i_<=n-1;i_++)
121            {
122                wtemp[i_] = w[i_];
123            }
124            for(i=0; i<=n-1; i++)
125            {
126                w[perm[i]] = wtemp[i];
127            }
128        }
129    }
130}
Note: See TracBrowser for help on using the repository browser.