示例#1
0
        public void AddVariablesMul(VariablesMulriplication variablesMulriplication)
        {
            this._isModified = true;

            var temp = variablesMulriplication.ToString();
            if (temp == "0" || temp == "")
                return;
            var v = this.variables.Find(vs => vs.EqualsVariablesWith(variablesMulriplication));
            if (v != null)
            {
                v.Constant += variablesMulriplication.Constant;
            }
            else
            {
                if (variablesMulriplication.IsFunction())
                {
                    //this.variables.Add(variablesMulriplication);
                    //(this + variablesMulriplication.ToFunction()).CopyTo(this);
                    var func = variablesMulriplication.ToFunction();
                    if (func.MathFunctions.Count != 0)
                    {
                        this.variables.Add(variablesMulriplication);
                    }
                    else
                    {
                        func.variables.ForEach(vs => this.AddVariablesMul(vs));
                    }
                }
                else
                {
                    this.variables.Add(variablesMulriplication);
                }
            }
        }
示例#2
0
        public Function(VariablesMulriplication v)
        {
            this._initProperties();

            this.AddVariablesMul(v);
        }
示例#3
0
        public Function(VariablesMulriplication[] variables)
        {
            this._initProperties();

            foreach (var v in variables)
            {
                this.AddVariablesMul(v);
            }
        }
示例#4
0
        public override VariablesMulriplication Derivative(string name)
        {
            VariablesMulriplication newVS = new VariablesMulriplication();
            Function e = new Function();
            
            this.variables.ForEach(vs => e.AddVariablesMul(vs.Derivative(name)));
            newVS.AddVariable(e);

#warning И без производных
            /*if (this.Degree != 1)
            {
                Function predF = this.Clone() as Function;
                predF.Degree--;
                newVS.AddVariable(predF);
                newVS.Constant *= this.Degree;
            }*/

            return newVS;
        }
 private static Function _mul(VariablesMulriplication vars, double d)
 {
     VariablesMulriplication vars2 = vars.Clone() as VariablesMulriplication;
     vars2.Constant *= d;
     return new Function(vars2);
 }
        private static Function _mul(VariablesMulriplication vars1, VariablesMulriplication vars2)
        {
            List<FunctionElement> vars = new List<FunctionElement>();
            vars1.variables.ForEach(v => vars.Add(v.Clone() as FunctionElement));
            var d = 1.0;

            vars2.variables.ForEach(delegate(FunctionElement v)
            {
                var temp = vars.Find(v1 => v1.Name.Equals(v.Name));
                //if (temp != null)
                //{
                //    temp.Degree += v.Degree;
                //}
                //else
                {
                    if (v.IsDouble())
                    {
                        d *= v.ToDouble();
                    }
                    else
                    {
                        vars.Add(v.Clone() as FunctionElement);
                    }
                }
            });
            return new Function(new VariablesMulriplication(vars.ToArray(), d * vars1.Constant * vars2.Constant));
        }
        private static Function _add(VariablesMulriplication vars1, VariablesMulriplication vars2)
        {
            List<FunctionElement> vars = new List<FunctionElement>();
            vars1.variables.ForEach(v => vars.Add(v.Clone() as FunctionElement));

            if (vars1.Equals(vars2))
            {
                return new Function(new VariablesMulriplication(vars.ToArray(), vars1.Constant + vars2.Constant));
            }

            List<FunctionElement> vars22 = new List<FunctionElement>();
            vars2.variables.ForEach(v => vars22.Add(v.Clone() as FunctionElement));
            return new Function(new VariablesMulriplication[]{
                new VariablesMulriplication(vars.ToArray(), vars1.Constant),
                new VariablesMulriplication(vars22.ToArray(), vars2.Constant)
            });
        }
        public bool EqualsVariablesWith(VariablesMulriplication v)
        {
            if (this.VarsCount != v.VarsCount)
                return false;

            for (int i = 0; i < v.variables.Count; i++)
            {
                if (!this.variables.Exists(vs => vs.Equals(v.variables[i])))
                {
                    return false;
                }
            }

            for (int i = 0; i < this.variables.Count; i++)
            {
                if (!v.variables.Exists(vs => vs.Equals(this.variables[i])))
                {
                    return false;
                }
            }

            return true;
        }