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

1 view (last 30 days)
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);

Answers (1)

Star Strider
Star Strider on 14 Jul 2022
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 Comments
Steven Lord
Steven Lord on 14 Jul 2022
The 'ArrayValued' option is listed on the integral function's documentation page, specifically in the Input Arguments section (the Name-Value Arguments subsection.)

Sign in to comment.

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!