Given coefficients, say, coeff = [1,2,3] I want to get a function for the polynomial: f(x) = coeff[1] * x + coeff[1] * x^2 + coeff[1] * x^3
First way
create_function(coeff) = x -> sum(coeff .* [x^k for k in 1:length(coeff)])
Second way
immutable Myfunction
coeff::Vector
end
call(f::Myfunction, x) = sum(f.coeff .* [x^k for k in 1:length(f.coeff)])
Then
coeff = [1,2,3]
foo = create_function(coeff)
bar = Myfunction(coeff)
foo(1.2)
bar(1.2)
Question: Which way is better in Julia?
