/// <summary> /// Run example /// </summary> /// <seealso cref="http://en.wikipedia.org/wiki/Spline_interpolation">Spline interpolation</seealso> public void Run() { // 1. Generate 10 samples of the function x*x-2*x on interval [0, 10] Console.WriteLine(@"1. Generate 10 samples of the function x*x-2*x on interval [0, 10]"); double[] points = Generate.LinearSpaced(10, 0, 10); var values = Generate.Map(points, TargetFunction); Console.WriteLine(); // 2. Create akima spline interpolation var method = CubicSpline.InterpolateAkima(points, values); Console.WriteLine(@"2. Create akima spline interpolation based on arbitrary points"); Console.WriteLine(); // 3. Check if interpolation support integration Console.WriteLine(@"3. Support integration = {0}", ((IInterpolation)method).SupportsIntegration); Console.WriteLine(); // 4. Check if interpolation support differentiation Console.WriteLine(@"4. Support differentiation = {0}", ((IInterpolation)method).SupportsDifferentiation); Console.WriteLine(); // 5. Differentiate at point 5.2 Console.WriteLine(@"5. Differentiate at point 5.2 = {0}", method.Differentiate(5.2)); Console.WriteLine(); // 6. Integrate at point 5.2 Console.WriteLine(@"6. Integrate at point 5.2 = {0}", method.Integrate(5.2)); Console.WriteLine(); // 7. Interpolate ten random points and compare to function results Console.WriteLine(@"7. Interpolate ten random points and compare to function results"); var rng = new MersenneTwister(1); for (var i = 0; i < 10; i++) { // Generate random value from [0, 10] var point = rng.NextDouble() * 10; Console.WriteLine(@"Interpolate at {0} = {1}. Function({0}) = {2}", point.ToString("N05"), method.Interpolate(point).ToString("N05"), TargetFunction(point).ToString("N05")); } Console.WriteLine(); }
/// <summary> /// Initializes a new instance of the <see cref="Palf"/> class. /// </summary> /// <param name="seed">The seed value.</param> /// <param name="threadSafe">if set to <c>true</c>, the class is thread safe.</param> /// <param name="shortLag">The ShortLag value</param> /// <param name="longLag">TheLongLag value</param> public Palf(int seed, bool threadSafe, int shortLag, int longLag) : base(threadSafe) { if (shortLag < 1) { throw new ArgumentException(Resources.ArgumentMustBePositive, "shortLag"); } if (longLag <= shortLag) { throw new ArgumentException("longLag"); } if (seed == 0) { seed = 1; } ShortLag = shortLag; // Align LongLag to number of worker threads. if (longLag % Control.NumberOfParallelWorkerThreads == 0) { LongLag = longLag; } else { LongLag = ((longLag / Control.NumberOfParallelWorkerThreads) + 1) * Control.NumberOfParallelWorkerThreads; } _x = new uint[LongLag]; var gen = new MersenneTwister(seed, threadSafe); for (var j = 0; j < LongLag; ++j) { _x[j] = (uint)(gen.NextDouble() * uint.MaxValue); } _i = LongLag; }
/// <summary> /// Run example /// </summary> /// <seealso cref="http://en.wikipedia.org/wiki/Interpolation">Interpolation</seealso> public void Run() { // 1. Generate 10 samples of the function 1/(1+x*x) on interval [-5, 5] Console.WriteLine(@"1. Generate 10 samples of the function 1/(1+x*x) on interval [-5, 5]"); double[] points; var values = SignalGenerator.EquidistantInterval(TargetFunction, -5, 5, 10, out points); Console.WriteLine(); // 2. Create a floater hormann rational pole-free interpolation based on arbitrary points // This method is used by default when create an interpolation using Interpolate.Common method var method = Interpolate.RationalWithoutPoles(points, values); Console.WriteLine(@"2. Create a floater hormann rational pole-free interpolation based on arbitrary points"); Console.WriteLine(); // 3. Check if interpolation support integration Console.WriteLine(@"3. Support integration = {0}", method.SupportsIntegration); Console.WriteLine(); // 4. Check if interpolation support differentiation Console.WriteLine(@"4. Support differentiation = {0}", method.SupportsDifferentiation); Console.WriteLine(); // 5. Interpolate ten random points and compare to function results Console.WriteLine(@"5. Interpolate ten random points and compare to function results"); var rng = new MersenneTwister(1); for (var i = 0; i < 10; i++) { // Generate random value from [0, 5] var point = rng.NextDouble() * 5; Console.WriteLine(@"Interpolate at {0} = {1}. Function({0}) = {2}", point.ToString("N05"), method.Interpolate(point).ToString("N05"), TargetFunction(point).ToString("N05")); } Console.WriteLine(); }
/// <summary> /// Run example /// </summary> /// <seealso cref="http://en.wikipedia.org/wiki/Spline_interpolation">Spline interpolation</seealso> public void Run() { // 1. Generate 20 samples of the function x*x-2*x on interval [0, 10] Console.WriteLine(@"1. Generate 20 samples of the function x*x-2*x on interval [0, 10]"); double[] points; var values = SignalGenerator.EquidistantInterval(TargetFunction, 0, 10, 20, out points); Console.WriteLine(); // 2. Create a linear spline interpolation based on arbitrary points var method = Interpolate.LinearBetweenPoints(points, values); Console.WriteLine(@"2. Create a linear spline interpolation based on arbitrary points"); Console.WriteLine(); // 3. Check if interpolation support integration Console.WriteLine(@"3. Support integration = {0}", method.SupportsIntegration); Console.WriteLine(); // 4. Check if interpolation support differentiation Console.WriteLine(@"4. Support differentiation = {0}", method.SupportsDifferentiation); Console.WriteLine(); // 5. Differentiate at point 5.2 Console.WriteLine(@"5. Differentiate at point 5.2 = {0}", method.Differentiate(5.2)); Console.WriteLine(); // 6. Integrate at point 5.2 Console.WriteLine(@"6. Integrate at point 5.2 = {0}", method.Integrate(5.2)); Console.WriteLine(); // 7. Interpolate ten random points and compare to function results Console.WriteLine(@"7. Interpolate ten random points and compare to function results"); var rng = new MersenneTwister(1); for (var i = 0; i < 10; i++) { // Generate random value from [0, 10] var point = rng.NextDouble() * 10; Console.WriteLine(@"Interpolate at {0} = {1}. Function({0}) = {2}", point.ToString("N05"), method.Interpolate(point).ToString("N05"), TargetFunction(point).ToString("N05")); } Console.WriteLine(); }