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

1 vue (au cours des 30 derniers jours)
Tmat
Tmat le 18 Mar 2020
Commenté : Tmat le 19 Mar 2020
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!

Réponse acceptée

David Goodmanson
David Goodmanson le 19 Mar 2020
Modifié(e) : David Goodmanson le 19 Mar 2020
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.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by