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

조회 수: 1 (최근 30일)
Tmat
Tmat 2020년 3월 18일
댓글: Tmat 2020년 3월 19일
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