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)

 채택된 답변

Steven Lord
Steven Lord 2021년 7월 16일

0 개 추천

Use the 'ArrayValued', true name-value pair argument as shown in the "Vector-Valued Function" example on the documentation page for the integral function.

댓글 수: 1

qfn
qfn 2021년 7월 16일
This fixes the problems stated. Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

qfn
2021년 7월 16일

댓글:

qfn
2021년 7월 16일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by