フィルターのクリア

Convolution of function handles

6 ビュー (過去 30 日間)
qfn
qfn 2021 年 7 月 16 日
コメント済み: qfn 2021 年 7 月 16 日
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 日
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 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by