How to create a function as the convolution of two functions? Thanks

1 次查看(过去 30 天)
Hi guys, I want to compute the convolution of two probability densities, and as an experiment I tried two uniform [0,1] densities:
fune=@(e)(e>=0).*(e<=1);
funz=@(z)(z>=0).*(z<=1);
funezt=@(ez,t)fune(ez-t).*funz(t);
funez=@(ez)integral(@(t)funezt(ez,t),0,2); % calculation using the definition of convolution
vecez=0:0.01:2;
vecfunez=funez(vecez);
plot(vecez,vecfunez)
However, this didn't work and the error message I got is:
Matrix dimensions must agree.
Error in convolutionexperiment>@(ez,t)fune(ez-t).*funz(t) (line 4)
funezt=@(ez,t)fune(ez-t).*funz(t);
Need some insignts and guidance on fixing this. Thanks!

采纳的回答

David Goodmanson
David Goodmanson 2020-3-19
编辑:David Goodmanson 2020-3-19
Hello James,
fune=@(e)(e>=0).*(e<=1);
funz=@(z)(z>=0).*(z<=1);
funezt=@(ez,t)fune(ez-t).*funz(t);
funez=@(ez)integral(@(t)funezt(ez,t),0,2,'ArrayValued',true); % <--
vecez=0:0.01:2;
vecfunez=funez(vecez);
plot(vecez,vecfunez)
A useful Matlab option.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by