필터 지우기
필터 지우기

How to do this double integration using integral2? Thanks!

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

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 3월 19일
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
Tmat
Tmat 2020년 3월 19일
Thanks a lot, Ameer, it worked!
Ameer Hamza
Ameer Hamza 2020년 3월 19일
Glad to be of help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Monte-Carlo에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by