Warning using integral function: Function behaves unexpectedly on array inputs
조회 수: 1 (최근 30일)
이전 댓글 표시
fplot(@(E) Current(E))
Current(1)
function test_integral = Current(V)
test_integral = integral(@(E) temp(E,V), -inf, inf);
function tempf = temp(E,V)
tempf = V.*exp(-(E.^2));
end
end
This is basically my code. Running this gives an error message of
Warning: Function behaves unexpectedly on array inputs. To improve performance, properly vectorize your function to return an output with the same size and
shape as the input arguments.
> In matlab.graphics.function.FunctionLine>getFunction
In matlab.graphics.function/FunctionLine/updateFunction
In matlab.graphics.function/FunctionLine/set.Function_I
In matlab.graphics.function/FunctionLine/set.Function
In matlab.graphics.function.FunctionLine
In fplot>singleFplot (line 245)
In fplot>@(f)singleFplot(cax,{f},limits,extraOpts,args) (line 200)
In fplot>vectorizeFplot (line 200)
In fplot (line 166)
In test4 (line 4)
I think this has something to do with the integral function and fplot function colliding, but I don't know how any of the two functions can be substituted. Perhaps there is a way to vectorize the results of the Current function? Again, I don't know if this is even the right direction.
Help would be very much appreciated. Thanks in advance.
댓글 수: 0
채택된 답변
Dyuman Joshi
2024년 1월 9일
편집: Dyuman Joshi
2024년 1월 9일
Set the 'ArrayValued' property to 1 for the integral, so that it evaluates the integral of an array/vector valued function/integrand.
Current(1:4)
fplot(@(E) Current(E))
function test_integral = Current(V)
test_integral = integral(@(E) temp(E,V), -inf, inf, 'ArrayValued', 1);
function tempf = temp(E,V)
tempf = V.*exp(-(E.^2));
end
end
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!