/// <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;
        }
Exemple #2
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;
        }
        private Explicit3DFunction(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;
        }
Exemple #4
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;
		}
		/// <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;
		}
Exemple #6
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;
        }
		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;
		}
		/// <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;
		}