예제 #1
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;
        }
예제 #2
0
		public static Function CreateRealFunction(ExpressionTree tree)
		{
			switch (tree.Variables.Length)
			{
				case 0:
					return new Constant(tree.ToString());
				case 1:
					return new Explicit2DFunction(tree.ToString());
				case 2:
					return new Explicit3DFunction(tree.ToString());
				default:
					return null;
			}
				
		}
예제 #3
0
        public static Function CreateRealFunction(ExpressionTree tree)
        {
            switch (tree.Variables.Length)
            {
            case 0:
                return(new Constant(tree.ToString()));

            case 1:
                return(new Explicit2DFunction(tree.ToString()));

            case 2:
                return(new Explicit3DFunction(tree.ToString()));

            default:
                return(null);
            }
        }
		/// <summary>Differentiates symbolic expression by specified variable.</summary>
		/// <returns>bynary tree that represents derivative of source tree</returns>
		/// <param name="tree"><strong>ExpressionTree</strong> binary tree of expression.</param>
		/// <param name="diffVar">variable of differentiation</param>
		public static ExpressionTree Differentiate(ExpressionTree tree, string diffVar)
		{
			if (tree == null) throw new ArgumentNullException("tree");
			if (diffVar == null) throw new ArgumentNullException("diffVar");

			ExpressionTree diffTree = new ExpressionTree(df(tree.RootNode,diffVar));			
			
			diffTree.Simplify();
			
			return new ExpressionTree(diffTree.ToString());		
		}
예제 #5
0
        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;
        }
예제 #6
0
        private Function CalculateAnalyticDerivative()
        {
            string formula =
                String.Format("-(({0})/({1}))",
                              AnalyticDifferentiator.Differentiate(_expressionTree, _expressionTree.Variables[0]),
                              AnalyticDifferentiator.Differentiate(_expressionTree, _expressionTree.Variables[1]));

            ExpressionTree diffTree = new ExpressionTree(formula);

            switch (diffTree.Variables.Length)
            {
            case 0:
                return(new Constant(diffTree.ToString()));

            case 1:
                return(new Explicit2DFunction(diffTree.ToString()));

            case 2:
                return(new Implicit2DFunction(diffTree.ToString()));

            default:
                throw new InvalidOperationException();
            }
        }
예제 #7
0
        private Function CalculateAnalyticDerivative()
        {
            ExpressionTree diffTree = AnalyticDifferentiator.Differentiate(_expressionTree, _expressionTree.Variables[0]);

            switch (diffTree.Variables.Length)
            {
            case 0:
                return(new Constant(diffTree.ToString()));

            case 1:
                return(new Explicit2DFunction(diffTree));

            default:
                throw new InvalidOperationException();
            }
        }
예제 #8
0
        /// <summary>Differentiates symbolic expression by specified variable.</summary>
        /// <returns>bynary tree that represents derivative of source tree</returns>
        /// <param name="tree"><strong>ExpressionTree</strong> binary tree of expression.</param>
        /// <param name="diffVar">variable of differentiation</param>
        public static ExpressionTree Differentiate(ExpressionTree tree, string diffVar)
        {
            if (tree == null)
            {
                throw new ArgumentNullException("tree");
            }
            if (diffVar == null)
            {
                throw new ArgumentNullException("diffVar");
            }

            ExpressionTree diffTree = new ExpressionTree(df(tree.RootNode, diffVar));

            diffTree.Simplify();

            return(new ExpressionTree(diffTree.ToString()));
        }
		/// <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;
		}
예제 #10
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;
		}
예제 #11
0
		private Function CalculateAnalyticDerivative()
		{
			string formula = 
				String.Format("-(({0})/({1}))", 
				AnalyticDifferentiator.Differentiate(_expressionTree,_expressionTree.Variables[0]),
				AnalyticDifferentiator.Differentiate(_expressionTree,_expressionTree.Variables[1]));

			ExpressionTree diffTree = new ExpressionTree(formula);

			switch (diffTree.Variables.Length)
			{
				case 0:
					return new Constant(diffTree.ToString());
				case 1:
					return new Explicit2DFunction(diffTree.ToString());
				case 2:
					return new Implicit2DFunction(diffTree.ToString());
				default:
					throw new InvalidOperationException();
			}

		}