Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
Bruce Griffin
Bruce Griffin el 14 de Jul. de 2022
Comentada: Steven Lord el 14 de Jul. de 2022
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);

Respuestas (1)

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

Iniciar sesión para comentar.

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by