Borrar filtros
Borrar filtros

How to do this double integration using integral2? Thanks!

1 visualización (últimos 30 días)
Tmat
Tmat el 19 de Mzo. de 2020
Comentada: Ameer Hamza el 19 de Mzo. de 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!

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 19 de Mzo. de 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 comentarios
Tmat
Tmat el 19 de Mzo. de 2020
Thanks a lot, Ameer, it worked!
Ameer Hamza
Ameer Hamza el 19 de Mzo. de 2020
Glad to be of help.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by