示例#1
0
        private void EvaluateButton_Click(object sender, RoutedEventArgs e)
        {
            CurrentExpression     = SymbolicVariable.Parse(ExpressionTextBox.Text);
            ExpressionResult.Text = CurrentExpression.ToString();

            D3Chart.Title = CurrentExpression.ToString();

            ParametersPanel.Children.Clear();
            // create dynamic sliders for the expression.
            foreach (var p in CurrentExpression.InvolvedSymbols)
            {
                Slider s = new Slider()
                {
                    Name = p + "Slider", Tag = p
                };
                s.Minimum = double.Parse(MinimumTextBox.Text);
                s.Maximum = double.Parse(MaximumTextBox.Text);
                s.Value   = s.Minimum;

                s.ValueChanged += new RoutedPropertyChangedEventHandler <double>(Sliders_ValueChanged);

                ParametersPanel.Children.Add(new TextBlock {
                    Text = p
                });
                ParametersPanel.Children.Add(s);
            }


            lgraph.Points.Clear();
        }
        /// <summary>
        /// Differentiate operation for function.
        /// </summary>
        /// <param name="value">object of <see cref="QsScalar"/> that hold <see cref="AnyQuantity&lt;SymbolicVariable&gt;"/></param>
        /// <returns></returns>
        public override QsValue DifferentiateOperation(QsValue value)
        {
            QsScalar sval = (QsScalar)value;

            if (sval.ScalarType == ScalarTypes.SymbolicQuantity)
            {
                var dsv = sval.SymbolicQuantity.Value;

                string fname         = "_";
                string WholeFunction = string.Empty;
                if (this.FunctionBodyToken[0].TokenClassType == typeof(CurlyBracketGroupToken))
                {
                    // vector differentiation
                    // take every term in the vector and differentiate it
                    var           vcs = QsVar.VectorComponents(this.FunctionBodyToken[0]);
                    StringBuilder sc  = new StringBuilder();
                    sc.Append(fname + "(" + RemoveRedundantParameters(this.ParametersNames) + ") = ");
                    sc.Append("{ ");
                    foreach (var c in vcs)
                    {
                        SymbolicVariable nsv = SymbolicVariable.Parse(c);
                        int times            = (int)dsv.SymbolPower;
                        while (times > 0)
                        {
                            nsv = nsv.Differentiate(dsv.Symbol);
                            times--;
                        }
                        sc.Append(nsv.ToString());
                        sc.Append(" ");
                    }
                    sc.Append("}");

                    WholeFunction = sc.ToString();
                }
                else
                {
                    SymbolicVariable nsv = ToSymbolicVariable();
                    int times            = (int)dsv.SymbolPower;
                    while (times > 0)
                    {
                        nsv = nsv.Differentiate(dsv.Symbol);
                        times--;
                    }

                    WholeFunction = fname + "(" + RemoveRedundantParameters(this.ParametersNames) + ") = " + nsv.ToString();
                }


                return(QsFunction.ParseFunction(QsEvaluator.CurrentEvaluator, WholeFunction));
            }
            else
            {
                return(base.DifferentiateOperation(value));
            }
        }