public void calc() { int len = Barray.Length; // table phid-fz Vector <double> Fz_vector = mybuilder.Dense(len, i => Harray[i] * lz); Vector <double> phid_Fz_vector = mybuilder.Dense(len, i => Barray[i] * Sz + Fz_vector[i] * Pslot); // table phid-fy Vector <double> Fy_vector = mybuilder.Dense(len, i => Harray[i] * ly); Vector <double> phid_Fy_vector = mybuilder.Dense(len, i => Barray[i] * Sy); // reshape phid-fy, using interpolation to create new vector corresponding with phid_fy = phid_fz Vector <double> phid_vector = mybuilder.DenseOfVector(phid_Fz_vector);//same phid table for all LinearSpline ls = LinearSpline.Interpolate(phid_Fy_vector.ToArray(), Fy_vector.ToArray()); Vector <double> eqvFy_vector = mybuilder.Dense(len, i => ls.Interpolate(phid_vector[i])); // table f_phid Vector <double> f_phid = mybuilder.Dense(len, i => phid_vector[i] / Pd + Fz_vector[i] + eqvFy_vector[i] - (phiR - phiHFe - phid_vector[i]) / (PM + PFe + Pb)); // calc phiD ls = LinearSpline.Interpolate(f_phid.ToArray(), phid_vector.ToArray()); phiD = ls.Interpolate(0); FM = (phiR - phiHFe - phiD) / (PM + PFe + Pb); phib = FM * Pb; phiFe = phiHFe + FM * PFe; phiM = phiD + phib + phiFe; ls = LinearSpline.Interpolate(phid_vector.ToArray(), Fz_vector.ToArray()); Fz = ls.Interpolate(phiD); ls = LinearSpline.Interpolate(phid_vector.ToArray(), eqvFy_vector.ToArray()); Fy = ls.Interpolate(phiD); }
/// <summary> /// Correction #1 - The Previous Object /// Estimate how second-last object placement affects the difficulty of hitting current object. /// </summary> private static double calculatePreviousObjectPlacementCorrection(MovementExtractionParameters p) { if (p.SecondLastObject == null || p.LastToCurrent.RelativeLength == 0) { return(0); } Debug.Assert(p.SecondLastToLast != null); double movementLengthRatio = p.LastToCurrent.TimeDelta / p.SecondLastToLast.Value.TimeDelta; double movementAngleCosine = cosineOfAngleBetweenPairs(p.SecondLastToLast.Value, p.LastToCurrent); if (movementLengthRatio > movement_length_ratio_threshold) { if (p.SecondLastToLast.Value.RelativeLength == 0) { return(0); } double angleCorrection = correction_moving_spline.Interpolate(movementAngleCosine); double movingness = SpecialFunctions.Logistic(p.SecondLastToLast.Value.RelativeLength * 6 - 5) - SpecialFunctions.Logistic(-5); return(movingness * angleCorrection * 1.5); } if (movementLengthRatio < 1 / movement_length_ratio_threshold) { if (p.SecondLastToLast.Value.RelativeLength == 0) { return(0); } return((1 - movementAngleCosine) * SpecialFunctions.Logistic((p.SecondLastToLast.Value.RelativeLength * movementLengthRatio - 1.5) * 4) * 0.3); } p.LastObjectTemporallyCenteredBetweenNeighbours = true; // rescale SecondLastToLast so that it's comparable timescale-wise to LastToCurrent var timeNormalisedSecondLastToLast = -p.SecondLastToLast.Value.RelativeVector / p.SecondLastToLast.Value.TimeDelta * p.LastToCurrent.TimeDelta; // transform secondLastObject to coordinates anchored in lastObject double secondLastTransformedX = timeNormalisedSecondLastToLast.DotProduct(p.LastToCurrent.RelativeVector) / p.LastToCurrent.RelativeLength; double secondLastTransformedY = (timeNormalisedSecondLastToLast - secondLastTransformedX * p.LastToCurrent.RelativeVector / p.LastToCurrent.RelativeLength).L2Norm(); double correctionSecondLastFlow = AngleCorrection.FLOW_SECONDLAST.Evaluate(p.LastToCurrent.RelativeLength, secondLastTransformedX, secondLastTransformedY); double correctionSecondLastSnap = AngleCorrection.SNAP_SECONDLAST.Evaluate(p.LastToCurrent.RelativeLength, secondLastTransformedX, secondLastTransformedY); double correctionSecondLastStop = SpecialFunctions.Logistic(10 * Math.Sqrt(secondLastTransformedX * secondLastTransformedX + secondLastTransformedY * secondLastTransformedY + 1) - 12); p.SecondLastToCurrentFlowiness = SpecialFunctions.Logistic((correctionSecondLastSnap - correctionSecondLastFlow - 0.05) * 20); return(PowerMean.Of(new[] { correctionSecondLastFlow, correctionSecondLastSnap, correctionSecondLastStop }, -10) * 1.3); }
public InjectWithdrawRange GetInjectWithdrawRange(double inventory) { double maxInjectWithdrawRate = _maxInjectWithdrawLinear.Interpolate(inventory); double minInjectWithdrawRate = _minInjectWithdrawLinear.Interpolate(inventory); return(new InjectWithdrawRange(minInjectWithdrawRate, maxInjectWithdrawRate)); }
public double GetDF(Date date) { double rate = spline.Interpolate(date); double df = Math.Exp(-rate * (date - anchorDate.value) / 365.0); return(underlyingCurve.GetDF(date) * df); }
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 static IInterpolation GetLinearInterpolationMethod(Peak peak) { peak.GetXAndYValuesAsLists(out var xValues, out var yValues); IInterpolation interpolation = LinearSpline.Interpolate(xValues, yValues); return(interpolation); }
private void checkAndCreateSpline() { if (id_spline == null) { id_spline = LinearSpline.Interpolate(max_torques, idqs.Select(f => f.d)); iq_spline = LinearSpline.Interpolate(max_torques, idqs.Select(f => f.q)); maxTorque_spline = LinearSpline.Interpolate(idqs.Select(f => f.Magnitude), max_torques); } }
/// <summary> /// Get max speed possible for given torque. Condition: Umax, Imax and max-torque-per-ample /// </summary> /// <param name="t"></param> /// <returns></returns> public double GetMaxSpeedForTorque(double t) { if (speed_spline == null) { speed_spline = LinearSpline.Interpolate(torques, speeds); } return(speed_spline.Interpolate(t)); }
public void FitsAtSamplePoints() { IInterpolation ip = LinearSpline.Interpolate(_t, _y); for (int i = 0; i < _y.Length; i++) { Assert.AreEqual(_y[i], ip.Interpolate(_t[i]), "A Exact Point " + i); } }
private void InterpolateCvY(double value) { var interpColumnName = CvYColumnConverter.NameFromValue(value); var interpTable = new TableProcessing.Table("Interpolate " + interpColumnName); interpTable.AddColumn(tables.OrdinKtgr.Column("PY")); var floorValue = double.NegativeInfinity; var ceilValue = double.PositiveInfinity; for (var i = 0; i < tables.OrdinKtgr.DataTable.Columns.Count; i++) { var column = tables.OrdinKtgr.DataTable.Columns[i]; if (column.ColumnName.IndexOf("CvY_", StringComparison.Ordinal) != 0) { continue; } var CV_value = CvYColumnConverter.ValueFromName(column.ColumnName); if (CV_value < value) { floorValue = CV_value; } else if (CV_value > value) { ceilValue = CV_value; break; } } var floorStr = CvYColumnConverter.NameFromValue(floorValue); var ceilStr = CvYColumnConverter.NameFromValue(ceilValue); interpTable.AddColumn(tables.OrdinKtgr.Column(floorStr)); var column_res = interpTable.Column(interpColumnName); interpTable.AddColumn(tables.OrdinKtgr.Column(ceilStr)); interpTable.IterateRows(row => { double[] x = { floorValue, ceilValue }; double[] y = { row[floorStr].DoubleValue, row[ceilStr].DoubleValue }; var res = LinearSpline.Interpolate(x, y).Interpolate(value); row.Set(column_res.Name, res); }, column_res.Name); tables.OrdinKtgr.AddColumn(interpTable.Column(interpColumnName)); }
public override void Calculate() { Times = Generate.LinearSpaced(base.Samples, base.Start, base.Start + base.Duration); LinearSpline interpolator = (UserTimes.Length < 2) ? LinearSpline.InterpolateSorted(new double[] { UserTimes[0] + 1, UserTimes[0] }, new double[] { UserValues[0], UserValues[0] }) : LinearSpline.InterpolateSorted(UserTimes, UserValues); values = Times.Select(t => interpolator.Interpolate(t)).ToArray(); }
public void SupportsLinearCase(int samples) { double[] x, y, xtest, ytest; LinearInterpolationCase.Build(out x, out y, out xtest, out ytest, samples); IInterpolation ip = LinearSpline.Interpolate(x, y); for (int i = 0; i < xtest.Length; i++) { Assert.AreEqual(ytest[i], ip.Interpolate(xtest[i]), 1e-15, "Linear with {0} samples, sample {1}", samples, i); } }
public Func <double, double> MakeInterpolator(IEnumerable <double> x, IEnumerable <double> y) { SplineBoundaryCondition bc; int xlength = x.Count(); int mode = InterpolationModeComboBox.SelectedIndex; if (mode == 0 || mode == 1) { int order; order = mode * 2 + 1; // linear => 1; cubic => 3 int npoints; if (!int.TryParse(extrapolationPointsTextBox.Text, out npoints)) { throw new Exception("Cannot parse number of points"); } if (npoints > xlength) { throw new Exception("Too many points required"); } if (npoints < order) { throw new Exception("More points must be used"); } var leftInterp = Fit.PolynomialFunc(x.Take(npoints).ToArray(), y.Take(npoints).ToArray(), order); var rightInterp = Fit.PolynomialFunc(x.Reverse().Take(npoints).Reverse().ToArray(), y.Reverse().Take(npoints).Reverse().ToArray(), order); double middlex = x.Skip((int)(xlength / 2)).First(); return(x2 => (x2 < middlex)?leftInterp(x2) : rightInterp(x2)); } else if (mode == 5) { IInterpolation I = LinearSpline.Interpolate(x, y); return(x2 => I.Interpolate(x2)); } else { if (InterpolationModeComboBox.SelectedIndex == 1) { bc = SplineBoundaryCondition.ParabolicallyTerminated; } else { bc = SplineBoundaryCondition.Natural; } IInterpolation I = CubicSpline.InterpolateBoundaries( x, y, bc, 0, bc, 0); // Values are unused for natural and parabolic termination return(x2 => I.Interpolate(x2)); } }
public Fdq GetCurrentForTorque(double torque) { checkAndCreateSpline(); double id = id_spline.Interpolate(torque); double iq = iq_spline.Interpolate(torque); return(new Fdq() { d = id, q = iq }); }
// This evaluates the SQUARED intergral of (S*Etan) public static double TFInt( Vector <Double> ETan_Z, Vector <Complex> ETan_RMS, Vector <Double> TF_Z, Vector <Complex> TF_Sr ) { int num_points = 5000; double zmin = Math.Max(TF_Z.Minimum(), ETan_Z.Minimum()); double zmax = Math.Min(TF_Z.Maximum(), ETan_Z.Maximum()); LinearSpline etansinterpR = LinearSpline.Interpolate( ETan_Z, ETan_RMS.Real()); LinearSpline etansinterpI = LinearSpline.Interpolate( ETan_Z, ETan_RMS.Imaginary()); LinearSpline TF_SrInterpR = LinearSpline.Interpolate( TF_Z, TF_Sr.Real()); LinearSpline TF_SrInterpI = LinearSpline.Interpolate( TF_Z, TF_Sr.Imaginary()); /*var ETanGridded = CreateVector.DenseOfEnumerable( * zvals.Select(z => new Complex( * etansinterpR.Interpolate(z), etansinterpI.Interpolate(z))) * ); * var SrGridded = CreateVector.DenseOfEnumerable( * zvals.Select(z => new Complex( * TF_SrInterpR.Interpolate(z), TF_SrInterpI.Interpolate(z))) * );*/ //var Z = SrGridded.PointwiseMultiply(ETanGridded); // This is the integrand, SR*Etan Func <double, Complex> SrEtan = (z) => { var s = new Complex( TF_SrInterpR.Interpolate(z), TF_SrInterpI.Interpolate(z)); var e = new Complex( etansinterpR.Interpolate(z), etansinterpI.Interpolate(z)); return(s * e); }; // And to integrate it, the real and imaginary components must be // separately computed. Complex sum = new Complex( NewtonCotesTrapeziumRule.IntegrateComposite( (z => SrEtan(z).Real), zmin, zmax, num_points), NewtonCotesTrapeziumRule.IntegrateComposite( (z => SrEtan(z).Imaginary), zmin, zmax, num_points) ); // Usually we need the magnitude squared (for the temperature calculations) // But, the caller may find the square root, if needed, for example for voltages double dT = sum.MagnitudeSquared(); return(dT); }
/// <summary> /// Interpolation of the interface points onto the equidistant Fourier points /// </summary> protected void InterpolateOntoFourierPoints(MultidimensionalArray interP, double[] samplP) { int numP = interP.Lengths[0]; // set interpolation data double[] independentVal = new double[numP + 2]; double[] dependentVal = new double[numP + 2]; for (int sp = 1; sp <= numP; sp++) { independentVal[sp] = interP[sp - 1, 0]; dependentVal[sp] = interP[sp - 1, 1]; } // extend the interpolation data for sample points at the boundary of the domain independentVal[0] = interP[numP - 1, 0] - DomainSize; dependentVal[0] = interP[numP - 1, 1]; independentVal[numP + 1] = interP[0, 0] + DomainSize; dependentVal[numP + 1] = interP[0, 1]; switch (this.InterpolationType) { case Interpolationtype.LinearSplineInterpolation: //LinearSplineInterpolation LinSpline = new LinearSplineInterpolation(); //LinSpline.Initialize(independentVal, dependentVal); var LinSpline = LinearSpline.Interpolate(independentVal, dependentVal); for (int sp = 0; sp < numFp; sp++) { samplP[sp] = LinSpline.Interpolate(FourierP[sp]); //invDFT_coeff[sp] = (Complex)samplP[sp]; } break; case Interpolationtype.CubicSplineInterpolation: //CubicSplineInterpolation CubSpline = new CubicSplineInterpolation(); //CubSpline.Initialize(independentVal, dependentVal); var CubSpline = CubicSpline.InterpolateNatural(independentVal, dependentVal); for (int sp = 0; sp < numFp; sp++) { samplP[sp] = CubSpline.Interpolate(FourierP[sp]); //invDFT_coeff[sp] = (Complex)samplP[sp]; } break; default: throw new NotImplementedException(); } }
public double Interpolate(double x) { //double value = interpolation.Interpolate(x); if (_xRange.Length < 3 || _yRange.Length < 3) { //return LinearSpline.InterpolateSorted(_xRange, _yRange).Interpolate(x); return(LinearSpline.Interpolate(_xRange, _yRange).Interpolate(x)); } else { return(CubicSpline.InterpolateNatural(_xRange, _yRange).Interpolate(x)); } }
/// <summary> /// Test using transient simulation /// The netlist should contain a transient simulation. The first exporter is tested to the reference /// </summary> /// <param name="netlist">Netlist</param> /// <param name="reft">Reference time values</param> /// <param name="refv">Reference values</param> protected void TestTransient(Netlist netlist, double[] reft, double[] refv) { var interpolation = LinearSpline.Interpolate(reft, refv); netlist.OnExportSimulationData += (object sender, SimulationData data) => { double time = data.GetTime(); double actual = netlist.Exports[0].Extract(data); double expected = interpolation.Interpolate(time); double tol = Math.Max(Math.Abs(actual), Math.Abs(expected)) * 1e-3 + 1e-12; Assert.AreEqual(expected, actual, tol); }; netlist.Simulate(); }
public void FirstDerivative() { IInterpolation ip = LinearSpline.Interpolate(_t, _y); Assert.That(ip.Differentiate(-3.0), Is.EqualTo(1.0)); Assert.That(ip.Differentiate(-2.0), Is.EqualTo(1.0)); Assert.That(ip.Differentiate(-1.5), Is.EqualTo(1.0)); Assert.That(ip.Differentiate(-1.0), Is.EqualTo(-3.0)); Assert.That(ip.Differentiate(-0.5), Is.EqualTo(-3.0)); Assert.That(ip.Differentiate(0.0), Is.EqualTo(1.0)); Assert.That(ip.Differentiate(0.5), Is.EqualTo(1.0)); Assert.That(ip.Differentiate(1.0), Is.EqualTo(1.0)); Assert.That(ip.Differentiate(2.0), Is.EqualTo(1.0)); Assert.That(ip.Differentiate(3.0), Is.EqualTo(1.0)); }
/// <summary> /// Interpolate the curve. /// </summary> /// <param name="date">The date at which the rate is required.</param> /// <returns></returns> public double InterpAtDate(Date date) { if (spline == null) { spline = LinearSpline.InterpolateSorted(this.dates, this.rates); } if (date.value < anchorDateValue) { throw new ArgumentException("Interpolation date (" + date.ToString() + ") is before the anchor date of the curve.(" + (new Date(anchorDateValue)).ToString() + ")"); } if (date.value > dates.Last()) { throw new ArgumentException("Interpolation date (" + date.ToString() + ") is after the last date on the curve.(" + (new Date(dates.Last())).ToString() + ")"); } return(spline.Interpolate(date)); }
public static object[,] InterpLinear([ExcelArgument(Description = "A vector of x values. Must be in increasing order")] double[] knownX, [ExcelArgument(Description = "A vector of y values. Must be the same length as knownX")] Double[] knownY, [ExcelArgument(Description = "x values at which interpolation is required.")] Double[,] requiredX) { LinearSpline spline = LinearSpline.InterpolateSorted(knownX, knownY); object[,] result = new object[requiredX.GetLength(0), requiredX.GetLength(1)]; for (int x = 0; x < requiredX.GetLength(0); x += 1) { for (int y = 0; y < requiredX.GetLength(1); y += 1) { result[x, y] = spline.Interpolate(requiredX[x, y]); } } return(result); }
private static double calcCorrection0Or3(double d, double x, double y, LinearSpline kInterp, LinearSpline scaleInterp, LinearSpline[,] coeffsInterps) { double correction_raw = kInterp.Interpolate(d); for (int i = 0; i < coeffsInterps.GetLength(0); i++) { double[] cs = new double[numCoeffs]; for (int j = 0; j < numCoeffs; j++) { cs[j] = coeffsInterps[i, j].Interpolate(d); } correction_raw += cs[3] * Math.Sqrt(Math.Pow((x - cs[0]), 2) + Math.Pow((y - cs[1]), 2) + cs[2]); } return(SpecialFunctions.Logistic(correction_raw) * scaleInterp.Interpolate(d)); }
public void DefiniteIntegral() { IInterpolation ip = LinearSpline.Interpolate(_t, _y); Assert.That(ip.Integrate(-4.0, -3.0), Is.EqualTo(-0.5)); Assert.That(ip.Integrate(-3.0, -2.0), Is.EqualTo(0.5)); Assert.That(ip.Integrate(-2.0, -1.0), Is.EqualTo(1.5)); Assert.That(ip.Integrate(-1.0, 0.0), Is.EqualTo(0.5)); Assert.That(ip.Integrate(0.0, 1.0), Is.EqualTo(-0.5)); Assert.That(ip.Integrate(1.0, 2.0), Is.EqualTo(0.5)); Assert.That(ip.Integrate(2.0, 3.0), Is.EqualTo(1.5)); Assert.That(ip.Integrate(3.0, 4.0), Is.EqualTo(2.5)); Assert.That(ip.Integrate(0.0, 4.0), Is.EqualTo(4.0)); Assert.That(ip.Integrate(-3.0, -1.0), Is.EqualTo(2.0)); Assert.That(ip.Integrate(-3.0, 4.0), Is.EqualTo(6.5)); Assert.That(ip.Integrate(0.5, 1.5), Is.EqualTo(0.0)); Assert.That(ip.Integrate(-2.5, -1.0), Is.EqualTo(1.875)); }
/// <summary> /// Setup the interpolated waveform /// </summary> /// <param name="ckt"></param> public override void Setup(Circuit ckt) { if (Time == null || Time.Length < 2 || Value == null || Value.Length < 2) { throw new CircuitException("No timepoints"); } // Sort the time points Array.Sort(Time, Value); // Create the linear interpolation interpolation = LinearSpline.Interpolate(Time, Value); per = Time[Time.Length - 1]; pw = double.PositiveInfinity; for (int i = 1; i < Time.Length; i++) { pw = Math.Min(pw, Time[i] - Time[i - 1]); } cindex = 0; }
private Fdq getCurrentForZone2(double torque, double speed, double Imax, double Umax) { VoltageLimitEllipse vle = null; string key = string.Format("{0},{1},{2}", Imax, Umax, speed); if (dict_vle.ContainsKey(key)) { vle = dict_vle[key]; } else { vle = buildVoltageLimitEllipse(speed, 100, Imax, Umax); dict_vle[key] = vle; } var range = Enumerable.Range(0, vle.maxtorque_point); // find point on Voltage limit ellipse that bring given torque LinearSpline spline = LinearSpline.Interpolate(range.Select(i => vle.torques[i]), range.Select(i => vle.curve[i].d)); double id = spline.Interpolate(torque); // get iq from this id var maxiq_point = vle.curve[vle.maxtorque_point]; var minid_point = vle.curve[vle.minid_point]; if (id < maxiq_point.d || minid_point.d < id) { return(default(Fdq)); } LinearSpline spline2 = LinearSpline.Interpolate(vle.curve.Select(f => f.d), vle.curve.Select(f => f.q)); double iq = spline2.Interpolate(id); return(new Fdq { d = id, q = iq, }); }
private void Button_Click(object sender, RoutedEventArgs e) { show.addData(sample0.ToArray(), sample1.ToArray(), 0); Stopwatch sw = new Stopwatch(); sw.Start(); var x = new double[Wnum]; var y = new double[Wnum]; IInterpolation spline = null; switch (cbM.SelectedIndex) { case 1: spline = CubicSpline.InterpolateAkimaSorted(sample0, sample1); break; default: spline = LinearSpline.Interpolate(sample0, sample1); break; } var Wdelta = (Wstop - Wstart) / Wnum; for (int i = 0; i < Wnum; i++) { y[i] = Wstart + i * Wdelta; x[i] = spline.Interpolate(y[i]); } sw.Stop(); var tm = sw.ElapsedMilliseconds; show.addData(y, x, 1); var sb = new StringBuilder(); sb.AppendLine("Time [ms] " + tm); Results = sb.ToString(); }
public Func <double, double> CreateInterpolator([NotNull] IEnumerable <double> xCoords, [NotNull] IEnumerable <double> yCoords) { if (xCoords == null) { throw new ArgumentNullException(nameof(xCoords)); } if (yCoords == null) { throw new ArgumentNullException(nameof(yCoords)); } if (xCoords.Count() != yCoords.Count()) { throw new ArgumentException("xCoords and yCoords must have the same number of elements."); } if (xCoords.Count() == 1) // Trivial case of a single point { double singleY = yCoords.Single(); return(x => singleY); } LinearSpline linearSpline = LinearSpline.Interpolate(xCoords, yCoords); // TODO use InterpolateSorted method? return(linearSpline.Interpolate); }
public override void RunAnalysis() { int len = Barray.Length; // table phid-fz Vector <double> Fz_vector = mybuilder.Dense(len, i => Harray[i] * lz); Vector <double> phid_Fz_vector = mybuilder.Dense(len, i => Barray[i] * Sz + Fz_vector[i] * Pslot); // table phid-fy Vector <double> Fy_vector = mybuilder.Dense(len, i => Harray[i] * ly); Vector <double> phid_Fy_vector = mybuilder.Dense(len, i => Barray[i] * Sy); // reshape phid-fy, using interpolation to create new vector corresponding with phid_fy = phid_fz Vector <double> phid_vector = mybuilder.DenseOfVector(phid_Fz_vector);//same phid table for all LinearSpline ls = LinearSpline.Interpolate(phid_Fy_vector.ToArray(), Fy_vector.ToArray()); Vector <double> eqvFy_vector = mybuilder.Dense(len, i => ls.Interpolate(phid_vector[i])); // table f_phid Vector <double> f_phid = mybuilder.Dense(len, i => phid_vector[i] / Pd + Fz_vector[i] + eqvFy_vector[i] - (phiR - phiHFe - phid_vector[i]) / (PM + PFe + Pb)); var Results = new PMAnalyticalResults(); Results.Analyser = this; this.Results = Results; // calc phiD ls = LinearSpline.Interpolate(f_phid.ToArray(), phid_vector.ToArray()); double phiD = ls.Interpolate(0); double FM = (phiR - phiHFe - phiD) / (PM + PFe + Pb); double phib = FM * Pb; double phiFe = phiHFe + FM * PFe; double phiM = phiD + phib + phiFe; ls = LinearSpline.Interpolate(phid_vector.ToArray(), Fz_vector.ToArray()); double Fz = ls.Interpolate(phiD); ls = LinearSpline.Interpolate(phid_vector.ToArray(), eqvFy_vector.ToArray()); double Fy = ls.Interpolate(phiD); double Bdelta = phiD / (L * wd * 1e-6); double BM = phiM / (L * wm * 1e-6); double HM = FM / (lm * 1e-3); double pc = phiM / (PM * FM); double Bz = phiD / Sz; double By = phiD / Sy; double Vz = Sz * lz; double Vy = Sy * ly; double ro_ = 7800;//kg/m^3 - specific weight double kPMz = 1.3 * Bz * Bz * ro_ * Vz; double kPMy = 1.3 * By * By * ro_ * Vy; Results.kPMz = kPMz; Results.kPMy = kPMy; // assign results Results.phiD = phiD; Results.Bdelta = Bdelta; Results.phiM = phiM; Results.BM = BM; Results.FM = FM; Results.HM = HM; Results.pc = pc; Results.phib = phib; Results.phiFe = phiFe; Results.Fz = Fz; Results.Fy = Fy; Results.Bz = Bz; Results.By = By; Results.wd = wd; Results.gammaM = gammaM; int q = Q / 3 / p / 2; double kp = Math.Sin(Math.PI / (2 * 3)) / (q * Math.Sin(Math.PI / (2 * 3 * q))); //Results.psiM = phiD * Nstrand * p * q * kp /*4 / Math.PI * Math.Sin(gammaM / 2 * Math.PI / 180)*/; // Ld, Lq //double In = 3;//Ampe whatever //double Fmm = q * kp * Nstrand * In; //double phidelta = (Fmm) / (1 / PMd + Fz / phiD + Fy / phiD) / 2;//2time,PMd=PM+Pdelta //double psi = phidelta * q * kp * Nstrand; //double LL = p * psi / In; //Results.LL = LL; //Results.Ld = 1.5 * LL;//M=-1/2L //phidelta = (Fmm) / (1 / PMq + Fz / phiD + Fy / phiD) / 2;// //psi = phidelta * q * kp * Nstrand; //LL = p * psi / In; //Results.Lq = 1.5 * LL; // Resistant Stator3Phase stator = Motor.Stator as Stator3Phase; Results.R = stator.resistancePhase; double delta2 = delta * 1.1; double ns = 4 / Math.PI * kp * stator.NStrands * q; double dmin = delta2; double alphaM = Motor.Rotor is VPMRotor ? (Motor.Rotor as VPMRotor).alphaM : 180; //double dmax = delta2 + lm / Math.Sin(alphaM); double dmax = delta2 + Constants.mu_0 * L * wd * 1e-3 * (1 / (PM + PFe + Pb) + Fy / phiD + Fz / phiD);//* wd / wm2 * ((VPMRotor)Motor.Rotor).mu_M; //double dmax = L * wd * 1e-3 * Constants.mu_0 / PMd; //double dmin2 = 1 / Math.PI * ((180 - gammaM) * dmin + gammaM * dmax) * Math.PI / 180 - 2 / Math.PI * Math.Sin(gammaM * Math.PI / 180) * (dmax - dmin); //double dmax2 = 1 / Math.PI * ((180 - gammaM) * dmin + gammaM * dmax) * Math.PI / 180 + 2 / Math.PI * Math.Sin(gammaM * Math.PI / 180) * (dmax - dmin); //double a1 = 0.5 * (1 / dmin2 + 1 / dmax2) * 1e3; //double a2 = 0.5 * (1 / dmin2 - 1 / dmax2) * 1e3; //double a1 = 0.5 * (dmin + dmax) / (dmin * dmax) * 1e3; //double a2 = 0.5 * (dmax - dmin) / (dmin * dmax) * 1e3; // test override double gm = gammaM * Math.PI / 180; double a1 = 1 / Math.PI * (gm / dmax + (Math.PI - gm) / dmin) * 1e3; double a2 = -2 / Math.PI * Math.Sin(gm) * (1 / dmax - 1 / dmin) * 1e3; double L1 = (ns / 2) * (ns / 2) * Math.PI * Motor.Rotor.RGap * Motor.GeneralParams.MotorLength * 1e-6 * a1 * 4 * Math.PI * 1e-7; double L2 = 0.5 * (ns / 2) * (ns / 2) * Math.PI * Motor.Rotor.RGap * Motor.GeneralParams.MotorLength * 1e-6 * a2 * 4 * Math.PI * 1e-7; Results.dmin = dmin; Results.dmax = dmax; Results.L1 = L1; Results.L2 = L2; Results.Ld = 1.5 * (L1 - L2); Results.Lq = 1.5 * (L1 + L2); double psim = 2 * Math.Sin(gammaM * Math.PI / 180 / 2) * ns * Bdelta * Motor.Rotor.RGap * Motor.GeneralParams.MotorLength * 1e-6; Results.psiM = psim; // current demagnetizing //Results.Ikm = 2 * phiR / PM / (kp * Nstrand * q); //old double hck = Motor.Rotor is VPMRotor ? (Motor.Rotor as VPMRotor).Hck : 0; Results.Ikm = Math.PI * (hck - HM) * lm * 1e-3 / (2 * q * Nstrand * kp); dataValid = (Results.Ld > 0 && Results.Lq > 0 && Results.psiM >= 0 && gm > 0); }
/// <summary> /// Create a piecewise linear interpolation based on arbitrary points. /// </summary> /// <param name="points">The sample points t.</param> /// <param name="values">The sample point values x(t).</param> /// <returns> /// An interpolation scheme optimized for the given sample points and values, /// which can then be used to compute interpolations and extrapolations /// on arbitrary points. /// </returns> /// <remarks> /// if your data is already sorted in arrays, consider to use /// MathNet.Numerics.Interpolation.LinearSpline.InterpolateSorted /// instead, which is more efficient. /// </remarks> public static IInterpolation Linear(IEnumerable <double> points, IEnumerable <double> values) { return(LinearSpline.Interpolate(points, values)); }
public virtual double Interpolate_Linear(double[] x, double[] y, double xValue) { return(LinearSpline.Interpolate(x, y).Interpolate(xValue)); }