public static double Derivative(RealFunction targetFunction, double x, DifferencesDirection direction) { if (targetFunction == null) { throw new ArgumentNullException("targetFunction"); } switch (direction) { case DifferencesDirection.Backward: { return(NumericalDifferentiator.BackwardDerivative(targetFunction, x)); } case DifferencesDirection.Central: { return(NumericalDifferentiator.CentralDerivative(targetFunction, x)); } case DifferencesDirection.Forward: { return(NumericalDifferentiator.ForwardDerivative(targetFunction, x)); } } throw new ArgumentOutOfRangeException("direction"); }
public BisectionSolver(RealFunction TargetFunction) { this.TargetFunction = TargetFunction; MaxIterations = 100; Tolerance = 1e-2; ThrowExceptionOnFailure = false; }
public Pigment(Colour d, Colour e, RealFunction f) { a = d; b = e; fr = f; scale = 1.0; }
public ToParametric2D(MulticastDelegate funcX, MulticastDelegate funcY) { _funcX = funcX as RealFunction; _funcY = funcY as RealFunction; _cFuncX = funcX as ConstantFunction; _cFuncY = funcY as ConstantFunction; }
public static double Derivative(RealFunction targetFunction, double x) { if (targetFunction == null) { throw new ArgumentNullException("targetFunction"); } return(NumericalDifferentiator.Derivative(targetFunction, x, DifferencesDirection.Central)); }
/// <summary> /// Creates function instance by specified <strong>RealFunction</strong> /// delegate. /// </summary> /// <param name="function"><strong>RealFunction</strong> delegate.</param> public Explicit2DFunction(RealFunction function) { if (function == null) throw new ArgumentNullException("function"); _function = function; base._delegate = _function; base._definitionType = DefinitionType.Numerical; }
public static RealFunction CreateForwardDelegate(RealFunction targetFunction) { if (targetFunction == null) { throw new ArgumentNullException("targetFunction"); } NumericalDifferentiator differentiator1 = new NumericalDifferentiator(targetFunction); return(new RealFunction(differentiator1.FormardDerivative)); }
public static double CentralDerivative(RealFunction targetFunction, double x) { double num1; if (targetFunction == null) { throw new ArgumentNullException("targetFunction"); } return(NumericalDifferentiator.CentralDerivative(targetFunction, x, out num1)); }
/// <summary> /// Creates function instance by specified <strong>RealFunction</strong> /// delegate. /// </summary> /// <param name="function"><strong>RealFunction</strong> delegate.</param> public Explicit2DFunction(RealFunction function) { if (function == null) { throw new ArgumentNullException("function"); } _function = function; base._delegate = _function; base._definitionType = DefinitionType.Numerical; }
private Explicit2DFunction(ExpressionTree tree) { _expressionTree = tree; _expression = tree.ToString(); ExpressionCompiler compiler = new ExpressionCompiler(_expressionTree); _function = (RealFunction)compiler.CreateDelegate(typeof(RealFunction)); base._delegate = _function; base._definitionType = DefinitionType.Analytic; }
public double Solve(double xa, double xb) { RealFunction f = TargetFunction; int i = 0; double x1 = xa; double x2 = xb; double fb = f(xb); double xmOld = 0.0; while (i <= MaxIterations) { i++; double xm = (x1 + x2) / 2; if (fb * f(xm) > 0) { x2 = xm; } else { x1 = xm; } if (Math.Abs(x2 - x1) <= Tolerance) { Status = SolverStatus.RootFound; IterationsNeeded = i; EstimatedError = Math.Abs(100 * (xm - xmOld) / xm); return(x2 - (x2 - x1) * f(x2) / (f(x2) - f(x1))); } xmOld = xm; } Status = SolverStatus.RootNotFound; if (ThrowExceptionOnFailure) { throw new RootNotFoundException("Kök bulunamadı!"); } if (IterationsNeeded >= MaxIterations) { throw new RootNotFoundException("Maksimum iterasyon sayısı aşıldı!"); } return(Double.NaN); }
public static double CentralDerivative(RealFunction targetFunction, double x, out double estimatedError) { if (targetFunction == null) { throw new ArgumentNullException("targetFunction"); } double step = Constants.SqrtEpsilon; double[] xCoord = new double[4]; double[] yCoord = new double[4]; int i = 0; while (i < 4) { xCoord[i] = x + ((i - 2) * step); yCoord[i] = targetFunction(xCoord[i]); i++; } for (int j = 1; j < 5; j++) { for (i = 0; i < (4 - j); i++) { yCoord[i] = (yCoord[i + 1] - yCoord[i]) / (xCoord[i + j] - xCoord[i]); } } double sum = Math.Abs((double)(((yCoord[0] + yCoord[1]) + yCoord[2]) + yCoord[3])); if (sum < Constants.SqrtEpsilon100) { sum = Constants.SqrtEpsilon100; } step = Math.Pow(Constants.SqrtEpsilon / (2 * sum), 0.33333333333333331); if (step > Constants.SqrtEpsilon100) { step = Constants.SqrtEpsilon100; } estimatedError = Math.Abs((double)(((100 * sum) * step) * step)); return((targetFunction(x + step) - targetFunction(x - step)) / (2 * step)); }
/// <example> /// <code lang="CS"> /// using System; /// using Genetibase.MathX.Core; /// /// namespace Genetibase.MathX.Core.Tests /// { /// public class Explicit2DFunctionSample /// { /// [STAThread] /// static void Main(string[] args) /// { /// // create function /// Explicit2DFunction function = new Explicit2DFunction("Sin(x)/x"); /// /// // calculate function _Function; /// for (int i = 0; i < 100; i++) /// { /// Console.WriteLine("f({0}) = {1}",i,function.ValueAt(i)); /// } /// /// } /// } /// } /// </code> /// </example> /// <summary>Creates function instance by specified expression.</summary> /// <exception cref="System.ArgumentNullException" caption=""></exception> /// <exception cref="System.ArgumentException" caption=""></exception> /// <exception cref="ExpressionSyntaxException" caption="ExpressionSyntaxException"></exception> /// <param name="expression">An mathematical expression with one variable.</param> public Explicit2DFunction(string expression) { if (expression == null) { throw new ArgumentNullException("expression"); } _expressionTree = new ExpressionTree(expression); if (_expressionTree.Variables.Length != 1) { throw new ArgumentException("Explicit 2D function must have one variable in expression", "expression"); } _expression = expression; ExpressionCompiler compiler = new ExpressionCompiler(_expressionTree); _function = (RealFunction)compiler.CreateDelegate(typeof(RealFunction)); base._delegate = _function; base._definitionType = DefinitionType.Analytic; }
public InverseExplicit2D(RealFunction x) { _x = x; }
// Methods private NumericalDifferentiator(RealFunction function) { this._function = function; }
public InverseExplicit2D(RealFunction x) { _x = x; }
public static RealFunction InverseFunction(RealFunction function) { return new InverseExplicit2D(function).CreateDelegate(); }
public ToParametric3D(MulticastDelegate funcX,MulticastDelegate funcY, MulticastDelegate funcZ) { _funcX = funcX as RealFunction; _funcY = funcY as RealFunction; _funcZ = funcZ as RealFunction; _cFuncX = funcX as ConstantFunction; _cFuncY = funcY as ConstantFunction; _cFuncZ = funcZ as ConstantFunction; }
public Explicit2DFunctionPlotter(Explicit2DFunction function) { _function = function.ValueAt; }
/// <example> /// <code lang="CS"> /// using System; /// using Genetibase.MathX.Core; /// /// namespace Genetibase.MathX.Core.Tests /// { /// public class Explicit2DFunctionSample /// { /// [STAThread] /// static void Main(string[] args) /// { /// // create function /// Explicit2DFunction function = new Explicit2DFunction("Sin(x)/x"); /// /// // calculate function _Function; /// for (int i = 0; i < 100; i++) /// { /// Console.WriteLine("f({0}) = {1}",i,function.ValueAt(i)); /// } /// /// } /// } /// } /// </code> /// </example> /// <summary>Creates function instance by specified expression.</summary> /// <exception cref="System.ArgumentNullException" caption=""></exception> /// <exception cref="System.ArgumentException" caption=""></exception> /// <exception cref="ExpressionSyntaxException" caption="ExpressionSyntaxException"></exception> /// <param name="expression">An mathematical expression with one variable.</param> public Explicit2DFunction(string expression) { if (expression == null) throw new ArgumentNullException("expression"); _expressionTree = new ExpressionTree(expression); if (_expressionTree.Variables.Length != 1) throw new ArgumentException("Explicit 2D function must have one variable in expression","expression"); _expression = expression; ExpressionCompiler compiler = new ExpressionCompiler(_expressionTree); _function = (RealFunction) compiler.CreateDelegate(typeof(RealFunction)); base._delegate = _function; base._definitionType = DefinitionType.Analytic; }
public Explicit2DFunctionPlotter(Explicit2DFunction function) { _function = function.ValueAt; }
private Explicit2DFunction (ExpressionTree tree) { _expressionTree = tree; _expression = tree.ToString(); ExpressionCompiler compiler = new ExpressionCompiler(_expressionTree); _function = (RealFunction) compiler.CreateDelegate(typeof(RealFunction)); base._delegate = _function; base._definitionType = DefinitionType.Analytic; }
public static RealFunction InverseFunction(RealFunction function) { return(new InverseExplicit2D(function).CreateDelegate()); }