Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
Bruce Griffin
Bruce Griffin am 14 Jul. 2022
Kommentiert: Steven Lord am 14 Jul. 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);

Antworten (1)

Star Strider
Star Strider am 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 Kommentare
Star Strider
Star Strider am 14 Jul. 2022
My pleasure!
See the documentation on the integral function, specifically Name-Value Arguments.
Steven Lord
Steven Lord am 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.)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by