private double CountWaveFunctions(double e) { InitSystems(e); _t = new double[_nodesCount]; _psi = new double[_nodesCount]; _phi = new double[_nodesCount]; var solver = new Solver(_systemForward, -_l, _conditionValuesForward, _h, _nodesCount); var solutionPsi = solver.Solve(); for (int i = 0; i < _nodesCount; i++) { _t[i] = solutionPsi[i][0]; _psi[i] = solutionPsi[i][2]; } solver = new Solver(_systemBackward, _l, _conditionValuesBackward, -_h, _nodesCount); var solutionFi = solver.Solve(); for (int i = 0; i < _nodesCount; i++) { _phi[i] = solutionFi[_nodesCount - 1 - i][2]; } Scale(_psi); NormalizeMath(); NormalizeQuant(); _psiSpline = CubicSpline.InterpolateAkima(_t, _psi); _phiSpline = CubicSpline.InterpolateAkima(_t, _phi); return(_psiSpline.Differentiate(_t[_sewNode]) - _phiSpline.Differentiate(_t[_sewNode])); }
public void FitsAtArbitraryPoints(double t, double x, double maxAbsoluteError) { IInterpolation it = CubicSpline.InterpolateAkima(_t, _y); // TODO: Verify the expected values (that they are really the expected ones) Assert.AreEqual(x, it.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t); }
protected void UpdateInterpolation() { int count = _keyFrames.Count; var xs = new double[count]; var ys = new double[count]; for (int i = 0; i < count; ++i) { xs[i] = (double)_keyFrames[i].time; ys[i] = (double)_keyFrames[i].value; } if (count <= 1) { _interpolation = StepInterpolation.Interpolate(xs, ys); } else if (count <= 2) { _interpolation = LinearSpline.Interpolate(xs, ys); } else if (count <= 3) { _interpolation = MathNet.Numerics.Interpolate.Polynomial(xs, ys); } else if (count <= 4) { _interpolation = CubicSpline.InterpolateNatural(xs, ys); } else { _interpolation = CubicSpline.InterpolateAkima(xs, ys); } }
public void FitsAtSamplePoints() { IInterpolation it = CubicSpline.InterpolateAkima(_t, _y); for (int i = 0; i < _y.Length; i++) { Assert.AreEqual(_y[i], it.Interpolate(_t[i]), "A Exact Point " + i); } }
private double CountXSquareQuantAvg() { for (var i = 0; i < _nodesCount; i++) { _xQuantAvg[i] = _psi[i] * _t[i] * _t[i] * _psi[i]; } var xQiantAvgSpline = CubicSpline.InterpolateAkima(_t, _xQuantAvg); return(xQiantAvgSpline.Integrate(-_l, _l)); }
public void SupportsLinearCase(int samples) { double[] x, y, xtest, ytest; LinearInterpolationCase.Build(out x, out y, out xtest, out ytest, samples); IInterpolation it = CubicSpline.InterpolateAkima(x, y); for (int i = 0; i < xtest.Length; i++) { Assert.AreEqual(ytest[i], it.Interpolate(xtest[i]), 1e-15, "Linear with {0} samples, sample {1}", samples, i); } }
public void InterpolateCurveAkima() // generates a smoother version of the random curve { List <SensitivityPoint> smoothCurve = new List <SensitivityPoint>(); double[] timestamp = sensCurve.Select(sensCurve => sensCurve.timeStamp).ToArray(); double[] randomsense = sensCurve.Select(sensCurve => sensCurve.sensitivity).ToArray(); CubicSpline spline = CubicSpline.InterpolateAkima(timestamp, randomsense); for (double timecode = 0; timecode < this.lenght; timecode += timestep) { SensitivityPoint sensPoint = new SensitivityPoint(timecode, spline.Interpolate(timecode)); smoothCurve.Add(sensPoint); } sensCurve = smoothCurve; }
private double GetProbalilityDensity(double[] function) { var functionSquare = new double[_nodesCount]; for (var i = 0; i < _nodesCount; i++) { functionSquare[i] = function[i] * function[i]; } var functionSquareSpline = CubicSpline.InterpolateAkima(_t, functionSquare); var x = functionSquareSpline.Integrate(-_l, _l); return(functionSquareSpline.Integrate(-_l, _l)); }
protected Func <double, double> CreatePolynom(int index) { if (points[index].Count == 0) { points[index].Add(new DataPoint(currMin, 1)); points[index].Add(new DataPoint(currMax, 1)); } DataPoint[] currPoints = points[index].ToArray(); double[,] coeffs = new double[currPoints.Length, 2]; List <double> xv = new List <double>(); List <double> yv = new List <double>(); Func <double, double> linear = CreateLinear(index); for (int i = 0; i < currPoints.Length; i++) { xv.Add(currPoints[i].XValue); yv.Add(currPoints[i].YValues[0]); coeffs[i, 0] = currPoints[i].XValue; coeffs[i, 1] = currPoints[i].YValues[0]; } Random rnd = new Random(); while (xv.Count < 5) { int i = rnd.Next(xv.Count - 1); int j = i + 1; double x = (xv[i] + xv[j]) / 2; yv.Insert(j, linear(x)); xv.Insert(j, x); } var akima = CubicSpline.InterpolateAkima(xv, yv); return((x) => { double res = akima.Interpolate(x); if (res < 0) { return 0; } if (res > 1) { return 1; } return res; }); }
/// <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> /// Строит функция принадлежности в виде сплайна Акимы. /// </summary> /// <param name="points">Список точек для построения сплайна.</param> protected void InitializeAkima(List <KeyValuePair <double, double> > points) { var ordered = points.OrderBy((p) => p.Key).ToList(); var akima = CubicSpline.InterpolateAkima(ordered.Select((p) => p.Key), ordered.Select((p) => p.Value)); function = (x) => { double res = akima.Interpolate(x[0]); if (res < 0) { return(0); } if (res > 1) { return(1); } return(res); }; }
private static IReadOnlyCollection <DataPoint> GeneratePointsFromBitmap(Stream stream) { const double fmax = 19000.0; const double fmin = 20.0; const double dbrange = 16.0; const double dbmax = 1.0; const double sampleRate = 48000.0; const int sampleSize = 16384; // Create a Bitmap object from an image file. using var iBitmap = new Bitmap(stream); //using var oBitmap = new Bitmap(iBitmap.Width, iBitmap.Height); var first = 0; //var last = 0; double min = iBitmap.Height; double max = 0; // Get the color of a pixel within myBitmap. var points = new Collection <KeyValuePair <int, double> >(); for (var x = 0; x < iBitmap.Width; x++) { var list = new List <int>(); for (var y = 0; y < iBitmap.Height; y++) { var pixelColor = iBitmap.GetPixel(x, y); if ((pixelColor.R > 200) && (pixelColor.G < 25) && (pixelColor.B < 25)) { if (first == 0) { first = x; } //else last = x; //oBitmap.SetPixel(x, y, Color.FromArgb(255, 0, 0)); list.Add(y); } } if (list.Count > 0) { var a = iBitmap.Height - list.Average(); points.Add(new KeyValuePair <int, double>(x, a)); if (a < min) { min = a; } if (a > max) { max = a; } } } //var size = last - first + 1; var mag = max - min + 1; //calculate gain & offset var scale = dbrange / mag; var shift = dbmax - max * scale; //check //var n_min = min * scale + shift; //var n_max = max * scale + shift; //convert bitmap to frequency spectrum var ex = new List <double>(); var ey = new List <double>(); for (var x = 0; x < points.Count; x++) { var df = Math.Log10(fmax / fmin); //over aproximately 3 decades var f = 20.0 * Math.Pow(10.0, df * x / points.Count); //convert log horizontal image pixels to linear frequency scale in Hz var y = points[x].Value * scale + shift; //scale and shift vertical image pixels to correct magnitude in dB ex.Add(f); ey.Add(Math.Pow(10.0, y / 20.0)); } //interpolate frequency spectrum to match Audyssey responseData length var frequency = Enumerable.Range(0, sampleSize).Select(p => p * sampleRate / sampleSize).ToArray(); var spline = CubicSpline.InterpolateAkima(ex, ey); var frequencyPoints = new List <DataPoint>(); foreach (var f in frequency) { if (f < fmin) { // exptrapolate frequencyPoints.Add(new DataPoint(f, double.NegativeInfinity)); } else { frequencyPoints.Add(f > fmax ? new DataPoint(f, double.NegativeInfinity) : new DataPoint(f, 20 * Math.Log10(spline.Interpolate(f)))); } } //oBitmap.Save(Path.ChangeExtension(path, "jpg"), System.Drawing.Imaging.ImageFormat.Jpeg); return(frequencyPoints); }
private TradingRecommendation GetTradingRecommendationForCrossOver() { int[] Intervals = { 50, 200 }; TradingRecommendation Recommendation = new TradingRecommendation(); List <double[]> MovingAverageObject = new List <double[]>(); List <double> d1 = Statistics.MovingAverage( GetBusinessDayDataForRange(DateTime.Now, Intervals[0]). Select(s => Convert.ToDouble(s.Close)).ToArray(), Intervals[0]).ToList(); List <double> d2 = Statistics.MovingAverage( GetBusinessDayDataForRange(DateTime.Now, Intervals[1]). Select(s => Convert.ToDouble(s.Close)).ToArray(), Intervals[1]).ToList(); double[] xd = d1.ToArray(); double[] yd = d2.Skip(d2.Count() - d1.Count()).ToArray(); CubicSpline Curvedata = CubicSpline.InterpolateAkima( d1.Select((s, i2) => new { i2, s }) .Select(t => Convert.ToDouble(t.i2)).ToArray(), d1); while (d1.Count() != d2.Count()) { if (d1.Count() > d2.Count()) { d2.Insert(0, 0); } else { d1.Insert(0, 0); } } double[] intersects0 = Polyfit(xd, yd, 0); List <Tuple <int, double> > Intersects = new List <Tuple <int, double> >(); int i = 0; foreach (double di in yd) { if (di * 0.999 <= intersects0[0] && di * 1.001 >= intersects0[0]) { Intersects.Add(new Tuple <int, double>(i, di)); } i++; } /* * * * CubicSpline Curvedata = CubicSpline.InterpolateAkima( * d1.Select((s, i2) => new { i2, s }) * .Select(t => Convert.ToDouble(t.i2)).ToArray(), * d1); * * * while (d1.Count() != d2.Count()) * { * if (d1.Count() > d2.Count()) * { * d2.Insert(0, double.NaN); * } * else * { * d1.Insert(0, double.NaN); * } * } * List<Tuple<int, double>> Intersects = new List<Tuple<int, double>>(); * int i = 0; * foreach (double di in d1) * { * //need to add a little bit of gliding here as well... * if (!double.IsNaN(di) && !double.IsNaN(d2[i]) && (di <= d2[i]*0.92 && di >= d2[i] * 1.07)) * { * Intersects.Add(new Tuple<int, double>(i, di)); * } * i++; * }*/ try { int Sellmax = (Intersects.Where(x => Curvedata.Differentiate(x.Item2) < 0).Count() > 0) ? Intersects.Where(x => Curvedata.Differentiate(x.Item2) < 0).Last().Item1 : 0; int Buymax = (Intersects.Where(x => Curvedata.Differentiate(x.Item2) > 0).Count() > 0) ? Intersects.Where(x => Curvedata.Differentiate(x.Item2) > 0).Last().Item1 : 0; if (Sellmax > Buymax && Sellmax > 0) { return(new TradingRecommendation( Instrument, ImperaturGlobal.GetMoney(0, Instrument.CurrencyCode), ImperaturGlobal.GetMoney(Convert.ToDecimal(Intersects.Where(x => x.Item1.Equals(Sellmax)).Last().Item2), Instrument.CurrencyCode), DateTime.Now, DateTime.Now, TradingForecastMethod.Crossover )); } if (Buymax > Sellmax && Buymax > 0) { return(new TradingRecommendation( Instrument, ImperaturGlobal.GetMoney(Convert.ToDecimal(Intersects.Where(x => x.Item1.Equals(Buymax)).Last().Item2), Instrument.CurrencyCode), ImperaturGlobal.GetMoney(0, Instrument.CurrencyCode), DateTime.Now, DateTime.Now, TradingForecastMethod.Crossover )); } } catch (Exception ex) { int gg = 0; } return(Recommendation); }
public void LoadTrajectory(com.robotraconteur.robotics.trajectory.JointTrajectory traj, double speed_ratio) { if (traj.joint_names.Count > 0) { if (!Enumerable.SequenceEqual(traj.joint_names, joint_names)) { throw new ArgumentException("Joint names in trajectory must match robot joint names"); } } if (traj.waypoints == null) { throw new ArgumentException("Waypoint list must not be null"); } if (traj.waypoints.Count < 5) { throw new ArgumentException("Waypoint list must contain five or more waypoints"); } if (traj.waypoints[0].time_from_start != 0) { throw new ArgumentException("Trajectory time_from_start must equal zero for first waypoint"); } if (traj.interpolation_mode != com.robotraconteur.robotics.trajectory.InterpolationMode.default_ && traj.interpolation_mode != com.robotraconteur.robotics.trajectory.InterpolationMode.cubic_spline) { throw new ArgumentException($"Only default and cubic_spline interpolation supported for trajectory execution"); } int n_waypoints = traj.waypoints.Count; int n_joints = joint_names.Length; var traj_t = new double[n_waypoints]; List <double[]> traj_j = Enumerable.Range(1, n_joints).Select(i => new double[n_waypoints]).ToList(); double last_t = 0; for (int i = 0; i < n_waypoints; i++) { var w = traj.waypoints[i]; if (w.joint_position.Length != n_joints) { throw new ArgumentException($"Waypoint {i} invalid joint array length"); } if (w.joint_velocity.Length != n_joints && w.joint_velocity.Length != 0) { throw new ArgumentException($"Waypoint {i} invalid joint velocity array length"); } if (w.position_tolerance.Length != n_joints && w.position_tolerance.Length != 0) { throw new ArgumentException($"Waypoint {i} invalid tolerance array length"); } if (w.velocity_tolerance.Length != n_joints && w.velocity_tolerance.Length != 0) { throw new ArgumentException($"Waypoint {i} invalid tolerance array length"); } if (i > 0) { if (w.time_from_start / speed_ratio <= last_t) { throw new ArgumentException("time_from_start must be increasing"); } } for (int j = 0; j < n_joints; j++) { if (w.joint_position[j] > joint_max[j] || w.joint_position[j] < joint_min[j]) { throw new ArgumentException($"Waypoint {i} exceeds joint limits"); } if (w.joint_velocity.Length > 0) { if (Math.Abs(w.joint_velocity[j] * speed_ratio) > joint_vel_max[j]) { throw new ArgumentException($"Waypoint {i} exceeds joint velocity limits"); } } } if (i > 0) { var last_w = traj.waypoints[i - 1]; double dt = w.time_from_start / speed_ratio - last_w.time_from_start / speed_ratio; for (int j = 0; j < n_joints; j++) { double dj = Math.Abs(w.joint_position[j] - last_w.joint_position[j]); if (dj / dt > joint_vel_max[j]) { throw new ArgumentException($"Waypoint {i} exceeds joint velocity limits"); } } } traj_t[i] = w.time_from_start / speed_ratio; for (int j = 0; j < n_joints; j++) { traj_j[j][i] = w.joint_position[j]; } last_t = w.time_from_start / speed_ratio; } joint_splines = traj_j.Select(x => CubicSpline.InterpolateAkima(traj_t, x)).ToList(); max_t = last_t; joint_start = traj.waypoints[0].joint_position; joint_end = traj.waypoints.Last().joint_position; waypoint_times = traj_t; }
public Collection <DataPoint> GeneratePointsFromBitmap(string filename) { filename = Path.ChangeExtension(filename, "png"); if (File.Exists(filename)) { double fmax = 19000.0; double fmin = 20.0; double dbrange = 16.0; double dbmax = 1; double sampleRate = 48000; int sampleSize = 16384; // Create a Bitmap object from an image file. Bitmap iBitmap = new Bitmap(filename); Bitmap oBitmap = new Bitmap(iBitmap.Width, iBitmap.Height); int first = 0; int last = 0; int size = 0; double min = iBitmap.Height; double max = 0; double mag = 0; // Get the color of a pixel within myBitmap. Collection <KeyValuePair <int, double> > points = new Collection <KeyValuePair <int, double> >(); for (var x = 0; x < iBitmap.Width; x++) { List <int> list = new List <int>(); for (var y = 0; y < iBitmap.Height; y++) { Color pixelColor = iBitmap.GetPixel(x, y); if ((pixelColor.R > 200) && (pixelColor.G < 25) && (pixelColor.B < 25)) { if (first == 0) { first = x; } else { last = x; } oBitmap.SetPixel(x, y, Color.FromArgb(255, 0, 0)); list.Add(y); } } if (list.Count > 0) { var a = iBitmap.Height - list.Average(); points.Add(new KeyValuePair <int, double>(x, a)); if (a < min) { min = a; } if (a > max) { max = a; } } } size = last - first + 1; mag = max - min + 1; //calculate gain & offset double scale = dbrange / mag; double shift = dbmax - max * scale; //check double n_min = min * scale + shift; double n_max = max * scale + shift; //convert bitmap to frequency spectrum Collection <double> ex = new Collection <double>(); Collection <double> ey = new Collection <double>(); for (var x = 0; x < points.Count; x++) { double df = Math.Log10(fmax / fmin); //over aproximately 3 decades double f = 20.0 * Math.Pow(10.0, df * x / points.Count); //convert log horizontal image pixels to linear frequency scale in Hz double y = points[x].Value * scale + shift; //scale and shift vertical image pixels to correct magnitude in dB ex.Add(f); ey.Add(Math.Pow(10.0, y / 20.0)); } //interpolate frequency spectrum to match Audyssey responseData length double[] frequency = Enumerable.Range(0, sampleSize).Select(p => p * sampleRate / sampleSize).ToArray(); CubicSpline IA = CubicSpline.InterpolateAkima(ex, ey); Collection <DataPoint> frequency_points = new Collection <DataPoint>(); foreach (var f in frequency) { if (f < fmin) { // exptrapolate frequency_points.Add(new DataPoint(f, double.NegativeInfinity)); } else { if (f > fmax) { // exptrapolate frequency_points.Add(new DataPoint(f, double.NegativeInfinity)); } else { //interpolate frequency_points.Add(new DataPoint(f, 20 * Math.Log10(IA.Interpolate(f)))); } } } oBitmap.Save(Path.ChangeExtension(filename, "jpg"), System.Drawing.Imaging.ImageFormat.Jpeg); return(frequency_points); } else { return(null); } }
public void FewSamples() { Assert.That(() => CubicSpline.InterpolateAkima(new double[0], new double[0]), Throws.ArgumentException); Assert.That(() => CubicSpline.InterpolateAkima(new double[4], new double[4]), Throws.ArgumentException); Assert.That(CubicSpline.InterpolateAkima(new[] { 1.0, 2.0, 3.0, 4.0, 5.0 }, new[] { 2.0, 2.0, 2.0, 2.0, 2.0 }).Interpolate(1.0), Is.EqualTo(2.0)); }
public virtual double Interpolate_CubicSpline(double[] x, double[] y, double xValue) { return(CubicSpline.InterpolateAkima(x, y).Interpolate(xValue)); }
public override void ExecuteExample() { MathDisplay.WriteLine("<b>Linear interpolation between points</b>"); // 1. Generate 20 samples of the function x*x-2*x on interval [0, 10] MathDisplay.WriteLine(@"1. Generate 20 samples of the function x*x-2*x on interval [0, 10]"); double[] points = Generate.LinearSpaced(20, 0, 10); var values = Generate.Map <double, double>(points, TargetFunction1); MathDisplay.WriteLine(); // 2. Create a linear spline interpolation based on arbitrary points var method = Interpolate.Linear(points, values); MathDisplay.WriteLine(@"2. Create a linear spline interpolation based on arbitrary points"); MathDisplay.WriteLine(); // 3. Check if interpolation support integration MathDisplay.WriteLine(@"3. Support integration = {0}", method.SupportsIntegration); MathDisplay.WriteLine(); // 4. Check if interpolation support differentiation MathDisplay.WriteLine(@"4. Support differentiation = {0}", method.SupportsDifferentiation); MathDisplay.WriteLine(); // 5. Differentiate at point 5.2 MathDisplay.WriteLine(@"5. Differentiate at point 5.2 = {0}", method.Differentiate(5.2)); MathDisplay.WriteLine(); // 6. Integrate at point 5.2 MathDisplay.WriteLine(@"6. Integrate at point 5.2 = {0}", method.Integrate(5.2)); MathDisplay.WriteLine(); // 7. Interpolate ten random points and compare to function results MathDisplay.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; MathDisplay.WriteLine( @"Interpolate at {0} = {1}. Function({0}) = {2}", point.ToString("N05"), method.Interpolate(point).ToString("N05"), TargetFunction1(point).ToString("N05")); } MathDisplay.WriteLine(); // <seealso cref="http://en.wikipedia.org/wiki/Spline_interpolation">Spline interpolation</seealso> MathDisplay.WriteLine("<b>Akima spline interpolation</b>"); // 1. Generate 10 samples of the function x*x-2*x on interval [0, 10] MathDisplay.WriteLine(@"1. Generate 10 samples of the function x*x-2*x on interval [0, 10]"); points = Generate.LinearSpaced(10, 0, 10); values = Generate.Map <double, double>(points, TargetFunction1); MathDisplay.WriteLine(); // 2. Create akima spline interpolation method = CubicSpline.InterpolateAkima(points, values); MathDisplay.WriteLine(@"2. Create akima spline interpolation based on arbitrary points"); MathDisplay.WriteLine(); // 3. Check if interpolation supports integration MathDisplay.WriteLine(@"3. Support integration = {0}", ((IInterpolation)method).SupportsIntegration); MathDisplay.WriteLine(); // 4. Check if interpolation support differentiation MathDisplay.WriteLine(@"4. Support differentiation = {0}", ((IInterpolation)method).SupportsDifferentiation); MathDisplay.WriteLine(); // 5. Differentiate at point 5.2 MathDisplay.WriteLine(@"5. Differentiate at point 5.2 = {0}", method.Differentiate(5.2)); MathDisplay.WriteLine(); // 6. Integrate at point 5.2 MathDisplay.WriteLine(@"6. Integrate at point 5.2 = {0}", method.Integrate(5.2)); MathDisplay.WriteLine(); // 7. Interpolate ten random points and compare to function results MathDisplay.WriteLine(@"7. Interpolate ten random points and compare to function results"); rng = new MersenneTwister(1); for (var i = 0; i < 10; i++) { // Generate random value from [0, 10] var point = rng.NextDouble() * 10; MathDisplay.WriteLine( @"Interpolate at {0} = {1}. Function({0}) = {2}", point.ToString("N05"), method.Interpolate(point).ToString("N05"), TargetFunction1(point).ToString("N05")); } MathDisplay.WriteLine(); MathDisplay.WriteLine("<b>Barycentric rational interpolation without poles</b>"); // 1. Generate 10 samples of the function 1/(1+x*x) on interval [-5, 5] MathDisplay.WriteLine(@"1. Generate 10 samples of the function 1/(1+x*x) on interval [-5, 5]"); points = Generate.LinearSpaced(10, -5, 5); values = Generate.Map <double, double>(points, TargetFunctionWithoutPolesEx); MathDisplay.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 method = Interpolate.RationalWithoutPoles(points, values); MathDisplay.WriteLine(@"2. Create a floater hormann rational pole-free interpolation based on arbitrary points"); MathDisplay.WriteLine(); // 3. Check if interpolation support integration MathDisplay.WriteLine(@"3. Support integration = {0}", method.SupportsIntegration); MathDisplay.WriteLine(); // 4. Check if interpolation support differentiation MathDisplay.WriteLine(@"4. Support differentiation = {0}", method.SupportsDifferentiation); MathDisplay.WriteLine(); // 5. Interpolate ten random points and compare to function results MathDisplay.WriteLine(@"5. Interpolate ten random points and compare to function results"); rng = new MersenneTwister(1); for (var i = 0; i < 10; i++) { // Generate random value from [0, 5] var point = rng.NextDouble() * 5; MathDisplay.WriteLine( @"Interpolate at {0} = {1}. Function({0}) = {2}", point.ToString("N05"), method.Interpolate(point).ToString("N05"), TargetFunctionWithoutPolesEx(point).ToString("N05")); } MathDisplay.WriteLine(); MathDisplay.WriteLine("<b>Rational interpolation with poles</b>"); // 1. Generate 20 samples of the function f(x) = x on interval [-5, 5] MathDisplay.WriteLine(@"1. Generate 20 samples of the function f(x) = x on interval [-5, 5]"); points = Generate.LinearSpaced(20, -5, 5); values = Generate.Map <double, double>(points, TargetFunctionWithPolesEx); MathDisplay.WriteLine(); // 2. Create a burlish stoer rational interpolation based on arbitrary points method = Interpolate.RationalWithPoles(points, values); MathDisplay.WriteLine(@"2. Create a burlish stoer rational interpolation based on arbitrary points"); MathDisplay.WriteLine(); // 3. Check if interpolation support integration MathDisplay.WriteLine(@"3. Support integration = {0}", method.SupportsIntegration); MathDisplay.WriteLine(); // 4. Check if interpolation support differentiation MathDisplay.WriteLine(@"4. Support differentiation = {0}", method.SupportsDifferentiation); MathDisplay.WriteLine(); // 5. Interpolate ten random points and compare to function results MathDisplay.WriteLine(@"5. Interpolate ten random points and compare to function results"); rng = new MersenneTwister(1); for (var i = 0; i < 10; i++) { // Generate random value from [0, 5] var point = rng.Next(0, 5); MathDisplay.WriteLine( @"Interpolate at {0} = {1}. Function({0}) = {2}", point.ToString("N05"), method.Interpolate(point).ToString("N05"), TargetFunctionWithPolesEx(point).ToString("N05")); } MathDisplay.WriteLine(); }