public override FunctionElement SetVariableValue(string name, FunctionElement e) { Function newF = new Function(); this.variables.ForEach(v => newF += v.SetVariableValue(name, e)); //newF.Degree = this.Degree; //newF.Functions = new List<MathFunctions.IMathFunction>(this.Functions); newF.ForceAddFunctions(this); foreach (var mf in newF.MathFunctions) { for (int i = 0; i < mf.Item2.Length; i++) { mf.Item2[i] = mf.Item2[i].SetVariableValue(name, e); } } return newF.Recalc(); }
/* #region operator + //public static Function operator +(Function f1, Function f2) //{ // return Function._add(f1, f2); //} //public static Function operator +(Function f, VariablesMulriplication vs) //{ // return Function._add(f, new Function(vs)); //} //public static Function operator +(VariablesMulriplication vs, Function f) //{ // return f + vs; //} //public static Function operator +(Function f, FunctionElement v) //{ // return f + new Function(v); //} //public static Function operator +(FunctionElement v, Function f) //{ // return f + v; //} //public static Function operator +(Function f, double d) //{ // return f + new Function(d); //} //public static Function operator +(double d, Function f) //{ // return f + d; //} #endregion #region operator - //public static Function operator -(Function f1, Function f2) //{ // return f1 + f2 * -1; //} //public static Function operator -(Function f, VariablesMulriplication vs) //{ // return f + vs * -1; //} //public static Function operator -(VariablesMulriplication vs, Function f) //{ // return new Function(vs) - f; //} //public static Function operator -(Function f, FunctionElement v) //{ // return f - new Function(v); //} //public static Function operator -(FunctionElement v, Function f) //{ // return new Function(v) - f; //} //public static Function operator -(Function f, double d) //{ // return f + new Function(-d); //} //public static Function operator -(double d, Function f) //{ // return new Function(d) - f; //} #endregion #region operator * //public static Function operator *(Function f1, Function f2) //{ // return Function._mul(f1, f2); //} //public static Function operator *(Function f, VariablesMulriplication vs) //{ // return f * new Function(vs); //} //public static Function operator *(VariablesMulriplication vs, Function f) //{ // return f * vs; //} //public static Function operator *(Function f, FunctionElement v) //{ // return f * new Function(v); // if ((v is Variable || v.IsConstant()) && f.Degree == 1) // { // Function newF = new Function(); // foreach (VariablesMulriplication vars in f.variables) // { // newF += vars * v; // } // return newF; // } // else // { // return new Function(new VariablesMulriplication(new FunctionElement[] { f, v })); // } //} //public static Function operator *(FunctionElement v, Function f) //{ // return f * v; //} //public static Function operator *(Function f, double d) //{ // if (f.Degree != 1) // { // Function F = new Function(); // F.AddVariablesMul(new VariablesMulriplication(d)); // F.AddVariablesMul(new VariablesMulriplication(f)); // return F; // } // Function newF = new Function(); // foreach (VariablesMulriplication vars in f.variables) // { // newF += vars * d; // } // return newF; //} //public static Function operator *(double d, Function f) //{ // return f * d; //} #endregion #region operator / // public static Function operator /(Function f1, Function f2) // { //#warning Сделать деление функций // if (f2.IsConstant()) // { // return f1 / f2.ToDouble(); // } // if (f2.VarsCount > 1 || (f2.VarsCount == 0 && f2.ToDouble() == 0)) // { // Function f = f1.Clone() as Function; // Function f22 = f2.Clone() as Function; // f22.Degree *= -1; // f.variables.Add(new VariablesMulriplication(f2)); // return f; // throw new Exception("Я еще не умею так делить."); // } // Function res = new Function(); // VariablesMulriplication d = f2.variables.Find(v => v.VarsCount != 0); // foreach (var v in f1.variables) // { // res += v / d; // } // return res; // } // public static Function operator /(Function f, VariablesMulriplication vs) // { // Function newF = new Function(); // foreach (var v in f.variables) // { // newF += v / vs; // } // return newF; // } // public static Function operator /(VariablesMulriplication vs, Function f) // { // return new Function(vs) / f; // } // public static Function operator /(Function f, FunctionElement v) // { // Function newF = new Function(); // foreach (var vs in f.variables) // { // newF += vs / v; // } // return newF; // } // public static Function operator /(FunctionElement v, Function f) // { // return new Function(new VariablesMulriplication(v)) / f; // } // public static Function operator /(Function f, double d) // { // Function newF = new Function(); // foreach (var vs in f.variables) // { // newF += vs / d; // } // return newF; // } // public static Function operator /(double d, Function f) // { // return new Function(d) / f; // } #endregion */ public override object Clone() { List<VariablesMulriplication> vars = new List<VariablesMulriplication>(); foreach (var vs in this.variables) { if (vs.Constant != 0) { vars.Add(vs.Clone() as VariablesMulriplication); } } var temp = new Function(vars.ToArray()); temp.MathFunctions.Clear(); temp.ForceAddFunctions(this); return temp; }