1 | /*************************************************************************
|
---|
2 | Copyright (c) 2009, Sergey Bochkanov (ALGLIB project).
|
---|
3 |
|
---|
4 | >>> SOURCE LICENSE >>>
|
---|
5 | This program is free software; you can redistribute it and/or modify
|
---|
6 | it under the terms of the GNU General Public License as published by
|
---|
7 | the Free Software Foundation (www.fsf.org); either version 2 of the
|
---|
8 | License, or (at your option) any later version.
|
---|
9 |
|
---|
10 | This program is distributed in the hope that it will be useful,
|
---|
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | GNU General Public License for more details.
|
---|
14 |
|
---|
15 | A copy of the GNU General Public License is available at
|
---|
16 | http://www.fsf.org/licensing/licenses
|
---|
17 |
|
---|
18 | >>> END OF LICENSE >>>
|
---|
19 | *************************************************************************/
|
---|
20 |
|
---|
21 | using System;
|
---|
22 |
|
---|
23 | namespace alglib
|
---|
24 | {
|
---|
25 | public class taskgen
|
---|
26 | {
|
---|
27 | /*************************************************************************
|
---|
28 | This function generates 1-dimensional general interpolation task with
|
---|
29 | moderate Lipshitz constant (close to 1.0)
|
---|
30 |
|
---|
31 | If N=1 then suborutine generates only one point at the middle of [A,B]
|
---|
32 |
|
---|
33 | -- ALGLIB --
|
---|
34 | Copyright 02.12.2009 by Bochkanov Sergey
|
---|
35 | *************************************************************************/
|
---|
36 | public static void taskgenint1d(double a,
|
---|
37 | double b,
|
---|
38 | int n,
|
---|
39 | ref double[] x,
|
---|
40 | ref double[] y)
|
---|
41 | {
|
---|
42 | int i = 0;
|
---|
43 | double h = 0;
|
---|
44 |
|
---|
45 | System.Diagnostics.Debug.Assert(n>=1, "TaskGenInterpolationEqdist1D: N<1!");
|
---|
46 | x = new double[n];
|
---|
47 | y = new double[n];
|
---|
48 | if( n>1 )
|
---|
49 | {
|
---|
50 | x[0] = a;
|
---|
51 | y[0] = 2*AP.Math.RandomReal()-1;
|
---|
52 | h = (b-a)/(n-1);
|
---|
53 | for(i=1; i<=n-1; i++)
|
---|
54 | {
|
---|
55 | if( i!=n-1 )
|
---|
56 | {
|
---|
57 | x[i] = a+(i+0.2*(2*AP.Math.RandomReal()-1))*h;
|
---|
58 | }
|
---|
59 | else
|
---|
60 | {
|
---|
61 | x[i] = b;
|
---|
62 | }
|
---|
63 | y[i] = y[i-1]+(2*AP.Math.RandomReal()-1)*(x[i]-x[i-1]);
|
---|
64 | }
|
---|
65 | }
|
---|
66 | else
|
---|
67 | {
|
---|
68 | x[0] = 0.5*(a+b);
|
---|
69 | y[0] = 2*AP.Math.RandomReal()-1;
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 |
|
---|
74 | /*************************************************************************
|
---|
75 | This function generates 1-dimensional equidistant interpolation task with
|
---|
76 | moderate Lipshitz constant (close to 1.0)
|
---|
77 |
|
---|
78 | If N=1 then suborutine generates only one point at the middle of [A,B]
|
---|
79 |
|
---|
80 | -- ALGLIB --
|
---|
81 | Copyright 02.12.2009 by Bochkanov Sergey
|
---|
82 | *************************************************************************/
|
---|
83 | public static void taskgenint1dequidist(double a,
|
---|
84 | double b,
|
---|
85 | int n,
|
---|
86 | ref double[] x,
|
---|
87 | ref double[] y)
|
---|
88 | {
|
---|
89 | int i = 0;
|
---|
90 | double h = 0;
|
---|
91 |
|
---|
92 | System.Diagnostics.Debug.Assert(n>=1, "TaskGenInterpolationEqdist1D: N<1!");
|
---|
93 | x = new double[n];
|
---|
94 | y = new double[n];
|
---|
95 | if( n>1 )
|
---|
96 | {
|
---|
97 | x[0] = a;
|
---|
98 | y[0] = 2*AP.Math.RandomReal()-1;
|
---|
99 | h = (b-a)/(n-1);
|
---|
100 | for(i=1; i<=n-1; i++)
|
---|
101 | {
|
---|
102 | x[i] = a+i*h;
|
---|
103 | y[i] = y[i-1]+(2*AP.Math.RandomReal()-1)*h;
|
---|
104 | }
|
---|
105 | }
|
---|
106 | else
|
---|
107 | {
|
---|
108 | x[0] = 0.5*(a+b);
|
---|
109 | y[0] = 2*AP.Math.RandomReal()-1;
|
---|
110 | }
|
---|
111 | }
|
---|
112 |
|
---|
113 |
|
---|
114 | /*************************************************************************
|
---|
115 | This function generates 1-dimensional Chebyshev-1 interpolation task with
|
---|
116 | moderate Lipshitz constant (close to 1.0)
|
---|
117 |
|
---|
118 | If N=1 then suborutine generates only one point at the middle of [A,B]
|
---|
119 |
|
---|
120 | -- ALGLIB --
|
---|
121 | Copyright 02.12.2009 by Bochkanov Sergey
|
---|
122 | *************************************************************************/
|
---|
123 | public static void taskgenint1dcheb1(double a,
|
---|
124 | double b,
|
---|
125 | int n,
|
---|
126 | ref double[] x,
|
---|
127 | ref double[] y)
|
---|
128 | {
|
---|
129 | int i = 0;
|
---|
130 | double h = 0;
|
---|
131 |
|
---|
132 | System.Diagnostics.Debug.Assert(n>=1, "TaskGenInterpolation1DCheb1: N<1!");
|
---|
133 | x = new double[n];
|
---|
134 | y = new double[n];
|
---|
135 | if( n>1 )
|
---|
136 | {
|
---|
137 | for(i=0; i<=n-1; i++)
|
---|
138 | {
|
---|
139 | x[i] = 0.5*(b+a)+0.5*(b-a)*Math.Cos(Math.PI*(2*i+1)/(2*n));
|
---|
140 | if( i==0 )
|
---|
141 | {
|
---|
142 | y[i] = 2*AP.Math.RandomReal()-1;
|
---|
143 | }
|
---|
144 | else
|
---|
145 | {
|
---|
146 | y[i] = y[i-1]+(2*AP.Math.RandomReal()-1)*(x[i]-x[i-1]);
|
---|
147 | }
|
---|
148 | }
|
---|
149 | }
|
---|
150 | else
|
---|
151 | {
|
---|
152 | x[0] = 0.5*(a+b);
|
---|
153 | y[0] = 2*AP.Math.RandomReal()-1;
|
---|
154 | }
|
---|
155 | }
|
---|
156 |
|
---|
157 |
|
---|
158 | /*************************************************************************
|
---|
159 | This function generates 1-dimensional Chebyshev-2 interpolation task with
|
---|
160 | moderate Lipshitz constant (close to 1.0)
|
---|
161 |
|
---|
162 | If N=1 then suborutine generates only one point at the middle of [A,B]
|
---|
163 |
|
---|
164 | -- ALGLIB --
|
---|
165 | Copyright 02.12.2009 by Bochkanov Sergey
|
---|
166 | *************************************************************************/
|
---|
167 | public static void taskgenint1dcheb2(double a,
|
---|
168 | double b,
|
---|
169 | int n,
|
---|
170 | ref double[] x,
|
---|
171 | ref double[] y)
|
---|
172 | {
|
---|
173 | int i = 0;
|
---|
174 | double h = 0;
|
---|
175 |
|
---|
176 | System.Diagnostics.Debug.Assert(n>=1, "TaskGenInterpolation1DCheb2: N<1!");
|
---|
177 | x = new double[n];
|
---|
178 | y = new double[n];
|
---|
179 | if( n>1 )
|
---|
180 | {
|
---|
181 | for(i=0; i<=n-1; i++)
|
---|
182 | {
|
---|
183 | x[i] = 0.5*(b+a)+0.5*(b-a)*Math.Cos(Math.PI*i/(n-1));
|
---|
184 | if( i==0 )
|
---|
185 | {
|
---|
186 | y[i] = 2*AP.Math.RandomReal()-1;
|
---|
187 | }
|
---|
188 | else
|
---|
189 | {
|
---|
190 | y[i] = y[i-1]+(2*AP.Math.RandomReal()-1)*(x[i]-x[i-1]);
|
---|
191 | }
|
---|
192 | }
|
---|
193 | }
|
---|
194 | else
|
---|
195 | {
|
---|
196 | x[0] = 0.5*(a+b);
|
---|
197 | y[0] = 2*AP.Math.RandomReal()-1;
|
---|
198 | }
|
---|
199 | }
|
---|
200 | }
|
---|
201 | }
|
---|