/// <summary> /// Sum /// </summary> /// <param name="b">b coeff</param> /// <param name="xLeft">xLeft</param> /// <param name="xRight">xright</param> /// <returns>sum</returns> public double Sum(double b, double xLeft, double xRight) { IArithmetic function = ("(2*X0 + b + 1) * (1)").ToArithmetic(); function.Let("b", b); double sum = 0; function.Let("Zero", xLeft); // si b est pair double start; if (b % 2 == 0) { start = ("-(b+1)/2").ToArithmetic().Converting().ToDouble(); } else { start = ("-b/2").ToArithmetic().Converting().ToDouble(); } for (double x = start; x < xRight; ++x) { function.Let("X0", x); sum = sum + function.Converting().ToDouble(); } return(sum); }
/// <summary> /// Differential DY /// </summary> /// <param name="y">y</param> /// <param name="y0">y0</param> /// <returns>value</returns> public double Differential(double y, double y0) { IArithmetic function = Polynome2.functions["DY"]; function.Let("Y", y); function.Let("Y_0", y0); return(function.Converting().ToDouble()); }
/// <summary> /// Compute Y0 value /// </summary> /// <param name="x0">X0 value input</param> /// <returns>Y0 value output</returns> public double ComputeY0(double x0) { IArithmetic function = Polynome2.functions["Y_0"]; this.TermX0 = x0; function.Let("b", this.CoefficientB); function.Let("c", this.CoefficientC); function.Let("X_0", this.TermX0); return(function.Converting().Compute().ToDouble()); }
/// <summary> /// Sum /// </summary> /// <param name="xLeft">xleft</param> /// <param name="distance">d</param> /// <param name="xRight">xright</param> /// <returns>sum</returns> public IArithmetic Sum(double xLeft, double distance, double xRight) { IArithmetic function = ("1/" + distance.ToString() + " + [X0/2] ^2").ToArithmetic(); IArithmetic sum = null; function.Let("X0", xLeft); for (double x = xLeft; x < xRight; x = x + 1 / distance) { if (sum != null) { sum = new Addition(sum, function.Converting()); } else { sum = function.Converting(); } function.Let("X0", function.Converting()); } return(sum); }
/// <summary> /// Differential DX /// </summary> /// <param name="dx">dx</param> /// <param name="x0">x0</param> /// <returns>value</returns> public double DifferentialDX(double dx, double x0) { IArithmetic function = ("DX*[DX+Y']").ToArithmetic(); IArithmetic yPrime = ("2*X_0 + b").ToArithmetic(); function.Let("b", this.CoefficientB); function.Let("c", this.CoefficientC); function.Let("Y'", yPrime); function.Let("X_0", x0); return(function.Converting().ToDouble()); }
/// <summary> /// Differential DY /// </summary> /// <param name="y">y</param> /// <param name="y0">y0</param> /// <param name="b">coefficient b</param> /// <param name="c">coefficient c</param> /// <returns>value</returns> public double Differential(double y, double y0, double b, double c) { IArithmetic function = Polynome2.functions["DY"]; this.CoefficientB = b; this.CoefficientC = c; function.Let("b", this.CoefficientB); function.Let("c", this.CoefficientC); function.Let("Y", y); function.Let("Y_0", y0); return(function.Converting().ToDouble()); }
/// <summary> /// Gets Base Y /// </summary> /// <param name="y">y value</param> /// <returns>arithmetic function</returns> public IArithmetic GetBaseY(double y) { Base Y = new Base(10, Base.ConvertToReadable(y, 10)); // creates a polynome for X GrobnerPolynome p = new GrobnerPolynome(Y.Dimension - 1); IArithmetic a = p.PolynomeAsBase("p", "X"); // gestion variables Dictionary <string, IArithmetic> variables = new Dictionary <string, IArithmetic>(); Arithmetic.EventAddVariable += new EventHandler <KeyValuePair <string, IArithmetic> >((o, e) => { if (e.Value != null) { if (variables.ContainsKey(e.Key)) { variables[e.Key] = e.Value; } else { variables.Add(e.Key, e.Value); } } else { if (variables.ContainsKey(e.Key)) { variables.Remove(e.Key); } } }); Arithmetic.EventGetVariable = new Func <string, IArithmetic>((s) => { if (variables.ContainsKey(s)) { return(variables[s]); } else { return(null); } }); for (int index = Y.Dimension - 1; index >= 0; --index) { a.Let("p_" + index.ToString(), Y.Vector.ElementAt(index)); } a.Let("X", this.GetBaseX(3)); return(a.Converting()); }
/// <summary> /// Compute Y0 value /// </summary> /// <param name="x0">X0 value input</param> /// <param name="b">b coefficient input</param> /// <param name="c">c coefficient input</param> /// <param name="d">d coefficient input</param> /// <returns>Y0 value output</returns> public double ComputeY0(double x0, double b, double c, double d) { IArithmetic function = Polynome3.functions["Y_0"]; this.TermX0 = x0; this.CoefficientB = b; this.CoefficientC = c; this.CoefficientD = d; function.Let("b", this.CoefficientB); function.Let("c", this.CoefficientC); function.Let("d", this.CoefficientD); function.Let("X_0", this.TermX0); return(function.Converting().Compute().ToDouble()); }
/// <summary> /// Compute R1 /// </summary> /// <returns>return R1</returns> public double ComputeR1() { IArithmetic function = Polynome3.functions["R_1"]; function.Let("b", this.CoefficientB); function.Let("c", this.CoefficientC); function.Let("d", this.CoefficientD); function.Let("X_1", this.TermX1); function.Let("X_2", this.TermX2); function.Let("V", this.TermV); function.Let("Y", this.TermY); function.Let("A", Polynome3.functions["A"].Converting()); function.Let("U", Polynome3.functions["U"].Converting()); return(function.Converting().Compute().ToDouble()); }
/// <summary> /// Compute A value /// </summary> /// <param name="y">y search input</param> /// <param name="x1">x1 input value</param> /// <param name="x2">x2 input value</param> /// <param name="v">v input value</param> /// <returns>A value</returns> public double ComputeA(double y, double x1, double x2, double v) { IArithmetic function = Polynome3.functions["A"]; this.TermY = y; this.TermX1 = x1; this.TermX2 = x2; this.TermV = v; function.Let("b", this.CoefficientB); function.Let("c", this.CoefficientC); function.Let("d", this.CoefficientD); function.Let("X_1", this.TermX1); function.Let("X_2", this.TermX2); function.Let("V", this.TermV); return(function.Converting().Compute().ToDouble()); }
/// <summary> /// Sum /// </summary> /// <param name="b">b coeff</param> /// <param name="c">coeff c</param> /// <param name="x0">y</param> /// <returns>sum</returns> public double Sum2(double b, double c, double x0) { IArithmetic diffY, n; if (b % 2 == 0) { diffY = ("1 + 2*(n+b/2)").ToArithmetic(); } else { diffY = ("2*(n+1+(b-1)/2)").ToArithmetic(); } diffY.Let("b", b); diffY.Let("c", c); diffY.Let("n", x0); IArithmetic Y = ("DY + c").ToArithmetic(); Y.Let("DY", diffY.Converting().ToDouble()); return(Y.Converting().ToDouble()); }
/// <summary> /// Compute x2 output /// </summary> /// <param name="Y">y input</param> /// <param name="x0">x0 input</param> /// <returns>x2 output</returns> public double ComputeX2(double Y, double x0) { this.TermY = Y; this.TermX0 = x0; IArithmetic yPrime = Polynome2.functions["Y'"]; IArithmetic y0 = Polynome2.functions["Y_0"]; IArithmetic dy = Polynome2.functions["DY"]; IArithmetic functionDX = Polynome2.functions["DX_2"]; IArithmetic x2 = Polynome2.functions["X_2"]; x2.Let("b", this.CoefficientB); x2.Let("c", this.CoefficientC); x2.Let("X_0", this.TermX0); x2.Let("Y_0", y0.Converting().ToDouble()); x2.Let("Y", this.TermY); x2.Let("Y", Y); x2.Let("DY", dy); x2.Let("DX_2", functionDX); x2.Let("Y'", yPrime.Converting().ToDouble()); return(x2.Converting().Compute().ToDouble()); }