public UnaryFunction Parse(string expr) { CheckExpression(ref expr); string src = "using System;" + "using RootFinding;" + "class myfunclass:IUnaryFunction" + "{" + "public myfunclass(){}" + "public double Eval(double x)" + "{" + "return " + expr + ";" + "}" + "}"; CompilerResults results = m_Provider.CompileAssemblyFromSource(m_CompilerParameters, src); if (results.Errors.Count == 0 && results.CompiledAssembly != null) { Type ObjType = results.CompiledAssembly.GetType("myfunclass"); try { IUnaryFunction func = null; if (ObjType != null) { func = Activator.CreateInstance(ObjType) as IUnaryFunction; } return(new UnaryFunction(func.Eval)); } catch (Exception ex) { throw new MathExpressionParserException(GetExceptionMessage(ex.Message)); } } else { throw new MathExpressionParserException(GetExceptionMessage(results.Errors[0].ToString())); } }
/// <summary> /// Apply the given unary function to a list of values. /// </summary> /// <param name="f"> /// The unary function implementing <see cref="IUnaryFunction"/>. /// </param> /// <param name="x"> /// The given function is applied to all values in the given /// <see cref="IList"/>. /// </param> public static void Apply(IUnaryFunction f, IList x) { for (int i = 0; i < x.Count; i++) { x[i] = f.Value((double)x[i]); } }
public static T InputFilter <T>(this T builder, IUnaryFunction unaryFunction) where T : IUnaryFunctionHolder { builder.InputSource = unaryFunction; return(builder); }
public static IFuzzySet UnaryOperation(IFuzzySet fuzzySet, IUnaryFunction unary) { MutableFuzzySet A = new MutableFuzzySet(fuzzySet.GetDomain()); foreach (DomainElement e in fuzzySet.GetDomain()) { A.Set(e, unary.ValueAt(fuzzySet.GetValueAt(e))); } return(A); }
public static IFuzzySet UnaryOperation(IFuzzySet set, IUnaryFunction function) { var newSet = new MutableFuzzySet(set.GetDomain()); foreach (var element in newSet.GetDomain()) { newSet.Set(element, function.ValueAt(set.GetValueAt(element))); } return(newSet); }