I'm doing some nonlinear fitting in MATLAB.
With most details stripped away, I have two function handles, f = @(x) and g = @(A,x) , where A is some parameter vector.
I'd really like to make a new function handle C = @(A,x), which is the convolution of f with g using parameter A.
Naively, that would be..
c = @(A,x) integral ( @(s) f(s).*g(A,x-s),-inf,inf);
This works for single values--e.g. c(1,1), but c isn't a well behaved function handle -- it throws errors for c(1,[1,2])*, which renders c unusable in non-linear fit algorithms. I think that's because the integral function is vectorized, so when x is a singleton, it can put in whatever size array it wishes for s, but when x is a vector, it snags on that step. In theory I could use some kind of repmat to fix this problem, but that seems awfully sloppy.
For a few more details:
f = @(x) is a piecewise combination of a few different exponentials and input functions.
g is actually just an exponential decay -- g = @(A,x) exp(-A*x);
I could probably compute these things explicitely and that might end up being fastest anyways but f may not always be such a nice function in practice.
>> c(1,[1, 1])
Matrix dimensions must agree.
Error in @(s)f(s).*g(A,x-s)
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
Error in @(A,x)integral(@(s)f(s).*g(A,x-s),0,180)