コード例 #1
0
        private Implicit2DFunction(ExpressionTree tree)
        {
            _expressionTree = tree;

            _expression = _expressionTree.ToString();


            ExpressionCompiler compiler = new ExpressionCompiler(_expressionTree);

            _function = (BivariateRealFunction)compiler.CreateDelegate(typeof(BivariateRealFunction));

            base._delegate       = _function;
            base._definitionType = DefinitionType.Analytic;
        }
コード例 #2
0
ファイル: Constant.cs プロジェクト: xuchuansheng/GenXSource
		public Constant(string expression) 
		{
			if (expression == null)
				throw new ArgumentNullException("expression");

			_expressionTree = new ExpressionTree(_expression);

			if (_expressionTree.Variables.Length != 0)
				throw new ArgumentException("Constant function cant have any variable in expression","expression");

			_expression = expression;

			ExpressionCompiler compiler = new ExpressionCompiler(_expressionTree);
			_function = (ConstantFunction) compiler.CreateDelegate(typeof(ConstantFunction));			

			base._delegate = _function;
			base._definitionType = DefinitionType.Analytic;
		}
コード例 #3
0
		/// <summary>Initializes a function that defined by expression.</summary>
		/// <exception cref="System.ArgumentException" caption=""></exception>
		/// <exception cref="System.ArgumentNullException" caption=""></exception>
		/// <exception cref="ExpressionSyntaxException" caption="ExpressionSyntaxException"></exception>
		public Implicit2DFunction(string expression)
		{
			if (expression == null)
				throw new ArgumentNullException("expression");

			_expressionTree = new ExpressionTree(expression);

			if (_expressionTree.Variables.Length != 2)
				throw new ArgumentException("Implicit 2D function must have two variables in expression","expression");

			_expression = expression;



			ExpressionCompiler compiler = new ExpressionCompiler(_expressionTree);
			_function = (BivariateRealFunction) compiler.CreateDelegate(typeof(BivariateRealFunction));

			base._delegate = _function;
			base._definitionType = DefinitionType.Analytic;
		}
コード例 #4
0
        /// <example>
        ///     <code lang="CS">
        /// using System;
        /// using System.Drawing;
        ///
        /// using Genetibase.MathX.Core;
        /// using Genetibase.MathX.Core.Plotters;
        ///
        /// namespace Genetibase.MathX.Core.Tests
        /// {
        ///     public class Implicit3DFunctionSample
        ///     {
        ///         [STAThread]
        ///         static void Main(string[] args)
        ///         {
        ///             // create function
        ///             Implicit3DFunction function = new Implicit3DFunction("x^2 + y^2 + z^2 - 10^2");
        ///
        ///             // create function plotter to plot function in specified range
        ///             Implicit3DFunctionPlotter plotter = new Implicit3DFunctionPlotter(function);
        ///
        ///             // write function roots in [0,0 - 10,10] range
        ///             foreach (Point3D point in plotter.Plot(new Point3D(-20,-20,-20), new Point3D(20,20,20), 1,1,1))
        ///             {
        ///                 Console.WriteLine("Function root at point ({0},{1},{2})", point.X, point.Y, point.Z);
        ///             }
        ///         }
        ///     }
        /// }
        /// </code>
        /// </example>
        /// <exception cref="System.ArgumentException" caption=""></exception>
        /// <exception cref="System.ArgumentNullException" caption=""></exception>
        /// <exception cref="ExpressionSyntaxException" caption="ExpressionSyntaxException"></exception>
        /// <summary>Initializes a function that defined by expression.</summary>
        public Implicit3DFunction(string expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            _expressionTree = new ExpressionTree(expression);

            if (_expressionTree.Variables.Length != 3)
            {
                throw new ArgumentException("Implicit 3D function must have three variables in expression", "expression");
            }

            _expression = expression;

            ExpressionCompiler compiler = new ExpressionCompiler(_expressionTree);

            _function = (TrivariateRealFunction)compiler.CreateDelegate(typeof(TrivariateRealFunction));

            base._delegate       = _function;
            base._definitionType = DefinitionType.Analytic;
        }
コード例 #5
0
        public Constant(string expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            _expressionTree = new ExpressionTree(_expression);

            if (_expressionTree.Variables.Length != 0)
            {
                throw new ArgumentException("Constant function cant have any variable in expression", "expression");
            }

            _expression = expression;

            ExpressionCompiler compiler = new ExpressionCompiler(_expressionTree);

            _function = (ConstantFunction)compiler.CreateDelegate(typeof(ConstantFunction));

            base._delegate       = _function;
            base._definitionType = DefinitionType.Analytic;
        }
コード例 #6
0
		/// <example>
		/// 	<code lang="CS">
		/// using System;
		/// using Genetibase.MathX.Core;
		///  
		/// namespace Genetibase.MathX.Core.Tests
		/// {
		///     public class Parameter2DFunctionSample
		///     {        
		///         [STAThread]
		///         static void Main(string[] args)
		///         {
		///             // create function
		///             Parameter2DFunction function = new Parameter2DFunction("10*sin(t)","10*cos(t)");
		///  
		///             // calculate function _Function;
		///             for (int i = 0; i &lt; 100; i++)
		///             {
		///                 Console.WriteLine("f({0}) = ({1},{2})",i,function.ValueAt(i).X,function.ValueAt(i).Y);
		///             }
		///                         
		///         }
		///     }
		/// }
		/// </code>
		/// </example>
		/// <summary>Initializes a function that defined by delegate.</summary>
		public Parameter2DFunction(string expressionX,string expressionY)
		{
			if (expressionX == null)
				throw new ArgumentNullException("expressionX");
			if (expressionY == null)
				throw new ArgumentNullException("expressionY");

			_expressionTreeX = new ExpressionTree(expressionX);
			_expressionTreeY = new ExpressionTree(expressionY);

			if (_expressionTreeX.Variables.Length > 1)
				throw new ArgumentException("expressionX");
			if (_expressionTreeY.Variables.Length > 1)
				throw new ArgumentException("expressionY");			

			_expressionX = expressionX;
			_expressionY = expressionY;

			_expression = string.Format("{0};{1}",_expressionX,_expressionY);

			ExpressionCompiler compilerX = new ExpressionCompiler(_expressionTreeX);
			ExpressionCompiler compilerY = new ExpressionCompiler(_expressionTreeY);

			if (_expressionTreeX.Variables.Length == 0)
				_functionX = new Constant(_expressionTreeX.ToString());
			else
				_functionX = new Explicit2DFunction(_expressionTreeX.ToString());

			if (_expressionTreeY.Variables.Length == 0)
				_functionY = new Constant(_expressionTreeY.ToString());
			else
				_functionY = new Explicit2DFunction(_expressionTreeY.ToString());
			
			_function = DelegateFactory.CreateParameter2DFunctionDelegate(
				_functionX.ValueAt,_functionY.ValueAt);

			base._delegate = _function;
			base._definitionType = DefinitionType.Analytic;
		}
コード例 #7
0
		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;
		}
コード例 #8
0
		/// <example>
		/// 	<code lang="CS">
		/// using System;
		/// using Genetibase.MathX.Core;
		///  
		/// namespace Genetibase.MathX.Core.Tests
		/// {
		///     public class ParametricSurfaceSample
		///     {        
		///         [STAThread]
		///         static void Main(string[] args)
		///         {
		///             // create function
		///             ParametricSurface function = new ParametricSurface("u+v","u-v","u*v");
		///  
		///             // calculate function _Function;
		///             for (int u = 0; u &lt; 100; u++)
		///             for (int v = 0; v &lt; 100; v++)
		///             {
		///                 Console.WriteLine("f({0},{1}) = ({2},{3},{4})",
		///                     u,v,function.ValueAt(u,v).X,function.ValueAt(u,v).Y, 
		///                     function.ValueAt(u,v).Z);
		///             }
		///                         
		///         }
		///     }
		/// }
		/// </code>
		/// </example>
		public ParametricSurface(string expressionX,string expressionY,string expressionZ) 
		{
			if (expressionX == null) throw new ArgumentNullException("expressionX");
			if (expressionY == null) throw new ArgumentNullException("expressionY");
			if (expressionZ == null) throw new ArgumentNullException("expressionZ");

			_expressionTreeX = new ExpressionTree(expressionX);
			_expressionTreeY = new ExpressionTree(expressionY);
			_expressionTreeZ = new ExpressionTree(expressionZ);

			if (_expressionTreeX.Variables.Length > 2) throw new ArgumentException("expressionX");
			if (_expressionTreeY.Variables.Length > 2) throw new ArgumentException("expressionY");			
			if (_expressionTreeZ.Variables.Length > 2) throw new ArgumentException("expressionZ");			

			_expressionX = expressionX;
			_expressionY = expressionY;
			_expressionZ = expressionZ;

			_expression = string.Format("{0};{1};{2}",
				_expressionX,_expressionY,_expressionZ);

			ExpressionCompiler compiler = 
				new ExpressionCompiler(new ExpressionTree[] {
																_expressionTreeX,
																_expressionTreeY,
																_expressionTreeZ
															});
			
			_functionX = FunctionFactory.CreateRealFunction(_expressionTreeX);
			_functionY = FunctionFactory.CreateRealFunction(_expressionTreeY);
			_functionZ = FunctionFactory.CreateRealFunction(_expressionTreeZ);
			
			_function = (ParametricSurfaceDelegate)compiler.CreateDelegate(typeof(ParametricSurfaceDelegate),
				"return new Point3D({0},{1},{2});");

			base._delegate = _function;
			base._definitionType = DefinitionType.Analytic;
		}