How to do this double integration using integral2? Thanks!
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Tmat
am 19 Mär. 2020
Kommentiert: Ameer Hamza
am 19 Mär. 2020
Hi, I'm trying to write some code to calculate accumulated the probability of using integral2. Here is my code:
clear;
ae=-4;be=4;
az=-8;bz=8;
fune=@(e)1/(be-ae)*(e>=ae).*(e<=be); % density of e
funz=@(z)1/(bz-az)*(z>=az).*(z<=bz); % density of z
funezt=@(ez,t)fune(ez(:)-t).*funz(t);
funez=@(ez)integral(@(t)funezt(ez,t),az,bz,'ArrayValued',true); % density of ez=e+z computed via convolution
funez12=@(ez1,ez2)funez(ez1).*funez(ez2); % joint density of (ez1,ez2)
aaa=integral2(funez12,0,4,0,4); %double integration on [0,4]^2
However, this code didn't work and has the following error message:
Error using integral2Calc>integral2t/tensor (line 241)
Integrand output size does not match the input size.
Have no clue about how to fix it, and need some insights. Thanks!
0 Kommentare
Akzeptierte Antwort
Ameer Hamza
am 19 Mär. 2020
To use a function as input to integral2, the input and output dimension must be the same. However, in your case, if we input a 2x2 matrices to funez12, the output is 4x1. Changing the line like this will correct the error
funez12 = @(ez1,ez2)reshape(funez(ez1).*funez(ez2), size(ez1)); % joint density of (ez1,ez2)
However, the correct solution depends on how you interpret the entries in the matrix.
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Monte-Carlo finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!