I can't figure out this array issue using an integral command
조회 수: 2 (최근 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);
댓글 수: 0
답변 (1개)
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)
.
댓글 수: 3
Star Strider
2022년 7월 14일
My pleasure!
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.)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!