필터 지우기
필터 지우기

Integration of the zero function handle ie f(x)=@(x) 0

조회 수: 3 (최근 30일)
Drew Mitchell
Drew Mitchell 2016년 5월 10일
댓글: Drew Mitchell 2016년 5월 11일
I have a function that requires the integration of many functions and sometime that function is zero but I don't really know when that will be.... Unfortunately, integral(@(x)0,0,1) returns the following error; Output of the function must be the same size as the input. If FUN is an array-valued integrand, set the 'ArrayValued' option to true. How do I get around this? Any help would be great!!
Thanks
Drew

채택된 답변

Walter Roberson
Walter Roberson 2016년 5월 10일
integral(@(x) 0 * x, 0, 1)
or
integral(@(x) zeros(size(x)), 0, 1)
  댓글 수: 3
Walter Roberson
Walter Roberson 2016년 5월 10일
I seem to be having difficulty getting that automatically generated. matlabFunction does seem to reduce it down to a single 0.0
Here is a test you can use:
F = matlabFunction(YourExpression);
syms zzzzzz
Fzzzzz = F(zzzzzz);
if isempty(symvar(Fzzzzz))
F = @(x) Fzzzzzz * ones(size(x));
end
This should work for constants other than 0 as well.
Drew Mitchell
Drew Mitchell 2016년 5월 11일
Great thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by