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

1 次查看(过去 30 天)
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 个评论
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 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by