/// <summary> /// This is for resolving variables by setting the equation to zero. /// </summary> public Evaluator(SingleVariableEq function, params Parameter[] parameters) { Dependencies.AddRange(parameters); this.singleVarSetToZero = function; this.constantVal = double.MinValue; this.type = EvaluatorType.setToZero; }
public Series CalculateShape() { double dl = this[_dl] ; double dx = this[_dx] ; double dy = this[_dy] ; double ell = this[_ell] ; x1 = this[_x1] ; x2 = this[_x2] ; y2 = this[_y2] ; if (dl <= dx) return null; double C = Math.Sqrt(24 * (dl - dx) / (dx* dx * dx)); var A = new SingleVariableEq(i => 2 * Math.Sinh(dx * i * .5) - i *dl); var B = new SingleVariableEq(i => dx * Math.Cosh(dx * i * .5) - dl); var D = A.NewtonRaphson(B, C, 0, C * 1.1, 1.0e-12, 100); double x, y = 0; double x0 = ((x1 + x2) - Math.Log((ell + dy) / (ell - dy)) / C) * 0.5; double y0 = y2 - Math.Cosh((x2 - x0) * C) / C; x = x1; Series ser = new Series("rope"); dx = .01; while (x < x2) { y = Math.Cosh((x - x0) * C) / C + y0; ser.Points.Add(new DataPoint(x, y)); x += dx; } x = x2; ser.Points.Add(new DataPoint(x, y)); ser.ChartType = SeriesChartType.Point; return ser; }
public double GetTension() { double dl = this[_dl]; double dx = this[_dx]; double dy = this[_dy]; double ell = this[_ell]; x1 = this[_x1]; x2 = this[_x2]; y2 = this[_y2]; double y1 = this[_y1]; if (dl <= dx) return double.MinValue; //f(T) = var A = new SingleVariableEq(t => 2 * t * Math.Sinh((x2- x1) / (2*t)) - Math.Sqrt(ell.Sqrd() - (y2 - y1).Sqrd())); //f'(T) = var B = new SingleVariableEq(t => (2 * Math.Sinh((x2 - x1) / 2 * t) * t - (x2 - x1) * Math.Cosh((x2 - x1) / 2 * t)) / t); var lowerBoundOnT = Math.Sqrt((x2 - x1).Sqrd() / ((Math.Sqrt(ell.Sqrd() - (y2 - y1).Sqrd()) - (x2 - x1))* 24)); var tension = A.NewtonRaphson(lowerBoundOnT + .1, lowerBoundOnT, 10, 1.0e-12, 100); //Todo: test the value of the tension and don't return a bad value return tension; }
public double NumberOfIterationsToConvergence(double x, double y) { A = this[_g] / (x * this[_gamma].Sqrd()); B = x * this[_gamma] / this[_v0Mag]; if (B > 1) return double.MinValue; if (x > this[_v0Mag] / this[_gamma]) return double.MinValue; double xi1 = 0; double xib = Math.Sqrt(1 / B.Sqrd() - 1); xi0 = y / x; //Solve using an iterative function method var t = new SingleVariableEq(eqToSolve); int counter; Math.Atan(t.IterativeSolver(xi1, -xib, xib, 1.0e-10, 10000, out counter)); return (double)counter; }
//A bug popped up in this method, not sure why. private double SolveWithNewtonRaphson(double x, double y) { var t2 = new SingleVariableEq(i => y / x - A * (Math.Log(1 - B * Math.Sqrt(1 + i.Sqrd())) + B * Math.Sqrt(1 + i.Sqrd())) - i); double C = Math.Exp(-(-y / x + 1 + Math.Sqrt(1 / B.Sqrd() - 1) / A)); double initApprox1 = -Math.Sqrt((1 - C).Sqrd() / B.Sqrd() - 1); double initApprox2 = Math.Sqrt((1 - C).Sqrd() / B.Sqrd() - 1); var deriv = new SingleVariableEq(i => (A * B.Sqrd() * i) / (1 - B * Math.Sqrt(1 + i.Sqrd())) - 1); var theta = Math.Atan(t2.NewtonRaphson(deriv, 0, initApprox1, initApprox2, 1.0e-10, 500)); return theta; }
private double SolveUsingIterativeFunction(double x, double y) { A = this[_g] / (x * this[_gamma].Sqrd()); B = x * this[_gamma] / this[_v0Mag]; if (B > 1) return double.MinValue; if (x > this[_v0Mag] / this[_gamma]) return double.MinValue; double xi1 = 0; double xib = Math.Sqrt(1 / B.Sqrd() - 1); xi0 = y / x; //Solve using an iterative function method var t = new SingleVariableEq(eqToSolve); int counter; return Math.Atan(t.IterativeSolver(xi1, -xib, xib, 1.0e-10, 10000)); }
/// <summary> /// Finds the value x where f(x) = 0 /// </summary> public double NewtonRaphson(double approx, double xMin, double xMax, double eps, int maxiter) { SingleVariableEq derivative = new SingleVariableEq(i => this.Derivative(i)); return new SingleVariableEq(i => i - this.Evaluate(i) / derivative.Evaluate(i) ).IterativeSolver(approx, xMin, xMax, eps, maxiter); }