Hello,
I have a numerical analysis program which for simplicity calculates an algorithm similar to:
y = ax^3 + bx^2 + cx + d;
I calculate the values of a,b,c,d at runtime and would like to pass the following equivalent as a Func<double, double>
. Where I can set a value for X, and get Y.
y = 12x^3 + 13x^2 + 14x + 15;
Where 12,13,14,15 are the numbers calculated at runtime.
I realise this can be done by passing in a double array, like so: Func<double[], double>
but I am trying to avoid passing around the constants (which can be many).
Is there any way to set these numbers in a func at runtime?
(Preferably without making the calculation of a,b,c,d part of the Func<> itself? The calculation of a,b,c,d is 80% of the work)
E.g.:
a = ...
b = ...
c = ...
Func<x, double> {
((const)a) * x^3 + ((const)b) * x^2 + ((const)c) * x + 15;
}`
For every evaluation of ABCD - I will evaluate 10 x's.