-
Notifications
You must be signed in to change notification settings - Fork 11
svf.md
Richard Ambler edited this page Sep 7, 2023
·
1 revision
Home | Single variable functions | Multi-variable functions | About
function-tree defines a class called SingleVariableFunction
that constructs a function-like object from a string representation of a single variable function.
final f = SingleVariableFunction(fromExpression: '3 * cosh(x)');
print(f(3));
30.202985987333292
By default, 'x'
is taken to be the variable; if this is not what we want, we can state the name of the variable:
final f = SingleVariableFunction(
fromExpression: '3 * cosh(a)',
withVariable: 'a'
);
print(f(3));
30.202985987333292
A more succinct way to construct a SingleVariableFunction
instance is directly from a string:
final f = '3 * x'.toSingleVariableFunction();
print(f(100));
300.0