필터 지우기
필터 지우기

I can't figure out this array issue using an integral command

조회 수: 1 (최근 30일)
Bruce Griffin
Bruce Griffin 2022년 7월 14일
댓글: Steven Lord 2022년 7월 14일
Im trying to figure out an integral from -inf to inf on a meshgrid. I keep getting an error saying arrays dont match. How do I fix this issue?
To be clear I have a meshgrid for space and time [ZZ Time]. I have an integral that needs to be calculates at every ZZ and Time where zz is from -inf to inf
ZZ=linspace(0,100,10);
Time=linspace(0,100,10);
zeta=1;
D=.36;
con=(4*D*Time);
fun=@(zz) (pi*.con).^(-1/2)*exp(-(ZZ-zz).^2/(con)).*exp(-abs(ZZ)/zeta);
output=integral(fun,-Inf,Inf)
Arrays have incompatible sizes for this operation.
Error in project>@(zz)(pi*con).^(-1/2)*exp(-(ZZ-zz).^2/(con)).*exp(-abs(ZZ)/zeta) (line 16)
fun=@(zz) (pi*con).^(-1/2)*exp(-(ZZ-zz).^2/(con)).*exp(-abs(ZZ)/zeta);

답변 (1개)

Star Strider
Star Strider 2022년 7월 14일
Use the 'ArrayValued' name-value pair —
format longE
ZZ=linspace(0,100,10);
Time=linspace(0,100,10);
zeta=1;
D=.36;
con=(4*D*Time);
fun=@(zz) (pi*con).^(-1/2)*exp(-(ZZ-zz).^2/(con)).*exp(-abs(ZZ)/zeta);
output=integral(fun,-Inf,Inf, 'ArrayValued',1)
Warning: Inf or NaN value encountered.
output = 1×10
1.0e+00 * NaN 3.585461724440791e-10 3.789098101244014e-15 4.623767377964554e-20 5.984561921181428e-25 7.999873414812673e-30 1.091435935050444e-34 1.510186593157276e-39 2.111253553715579e-44 2.974882993765993e-49
.
  댓글 수: 3
Star Strider
Star Strider 2022년 7월 14일
My pleasure!
See the documentation on the integral function, specifically Name-Value Arguments.
Steven Lord
Steven Lord 2022년 7월 14일
The 'ArrayValued' option is listed on the integral function's documentation page, specifically in the Input Arguments section (the Name-Value Arguments subsection.)

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

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by