I'd like to dynamically construct a function that can then be referred to with a function handle for later use in Matlab functions such as integral(fun,a,b).
As an example imagine a function with terms:
(x-A)/(D-A) * (x-B)/(D-B) * (x-C)/(D-C)
where x is a variable and A,B,C,D are constants from a vector (call it K=[A,B,C,D]' as an example) generated by a different function.
I could do:
fun = @(x) (x-A)/(D-A) * (x-B)/(D-B) * (x-C)/(D-C)
However, this restricts me to three terms. I'd like to be able to take an arbitrary length vector of constants and generate a function of similar form to the one above. Normally this is easy in Matlab, but it seems like function handles expect 'x' to be a scalar, so something like:
prod( (x - K(1:3)) ./ K(4)-K(1:3) )
returns an error.