Convolution of function handles
4 次查看(过去 30 天)
显示 更早的评论
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.
*error here:
>> 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)
0 个评论
采纳的回答
Steven Lord
2021-7-16
Use the 'ArrayValued', true name-value pair argument as shown in the "Vector-Valued Function" example on the documentation page for the integral function.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Computations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!