[3839] | 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 |
|
---|
| 131 | System.Diagnostics.Debug.Assert(n>=1, "TaskGenInterpolation1DCheb1: N<1!");
|
---|
| 132 | x = new double[n];
|
---|
| 133 | y = new double[n];
|
---|
| 134 | if( n>1 )
|
---|
| 135 | {
|
---|
| 136 | for(i=0; i<=n-1; i++)
|
---|
| 137 | {
|
---|
| 138 | x[i] = 0.5*(b+a)+0.5*(b-a)*Math.Cos(Math.PI*(2*i+1)/(2*n));
|
---|
| 139 | if( i==0 )
|
---|
| 140 | {
|
---|
| 141 | y[i] = 2*AP.Math.RandomReal()-1;
|
---|
| 142 | }
|
---|
| 143 | else
|
---|
| 144 | {
|
---|
| 145 | y[i] = y[i-1]+(2*AP.Math.RandomReal()-1)*(x[i]-x[i-1]);
|
---|
| 146 | }
|
---|
| 147 | }
|
---|
| 148 | }
|
---|
| 149 | else
|
---|
| 150 | {
|
---|
| 151 | x[0] = 0.5*(a+b);
|
---|
| 152 | y[0] = 2*AP.Math.RandomReal()-1;
|
---|
| 153 | }
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 |
|
---|
| 157 | /*************************************************************************
|
---|
| 158 | This function generates 1-dimensional Chebyshev-2 interpolation task with
|
---|
| 159 | moderate Lipshitz constant (close to 1.0)
|
---|
| 160 |
|
---|
| 161 | If N=1 then suborutine generates only one point at the middle of [A,B]
|
---|
| 162 |
|
---|
| 163 | -- ALGLIB --
|
---|
| 164 | Copyright 02.12.2009 by Bochkanov Sergey
|
---|
| 165 | *************************************************************************/
|
---|
| 166 | public static void taskgenint1dcheb2(double a,
|
---|
| 167 | double b,
|
---|
| 168 | int n,
|
---|
| 169 | ref double[] x,
|
---|
| 170 | ref double[] y)
|
---|
| 171 | {
|
---|
| 172 | int i = 0;
|
---|
| 173 |
|
---|
| 174 | System.Diagnostics.Debug.Assert(n>=1, "TaskGenInterpolation1DCheb2: N<1!");
|
---|
| 175 | x = new double[n];
|
---|
| 176 | y = new double[n];
|
---|
| 177 | if( n>1 )
|
---|
| 178 | {
|
---|
| 179 | for(i=0; i<=n-1; i++)
|
---|
| 180 | {
|
---|
| 181 | x[i] = 0.5*(b+a)+0.5*(b-a)*Math.Cos(Math.PI*i/(n-1));
|
---|
| 182 | if( i==0 )
|
---|
| 183 | {
|
---|
| 184 | y[i] = 2*AP.Math.RandomReal()-1;
|
---|
| 185 | }
|
---|
| 186 | else
|
---|
| 187 | {
|
---|
| 188 | y[i] = y[i-1]+(2*AP.Math.RandomReal()-1)*(x[i]-x[i-1]);
|
---|
| 189 | }
|
---|
| 190 | }
|
---|
| 191 | }
|
---|
| 192 | else
|
---|
| 193 | {
|
---|
| 194 | x[0] = 0.5*(a+b);
|
---|
| 195 | y[0] = 2*AP.Math.RandomReal()-1;
|
---|
| 196 | }
|
---|
| 197 | }
|
---|
| 198 | }
|
---|
| 199 | }
|
---|