Why I get wrong in integral function?

조회 수: 2 (최근 30일)
JIANGWEN DONG
JIANGWEN DONG 2021년 2월 5일
답변: Steven Lord 2021년 2월 5일
fun = @(x) ((x.^3)+x+1)/((x^2)+1)^2;
f = integral(fun, 1,6);

답변 (2개)

Walter Roberson
Walter Roberson 2021년 2월 5일
fun = @(x) ((x.^3)+x+1)./((x.^2)+1).^2;

Steven Lord
Steven Lord 2021년 2월 5일
fun = @(x) ((x.^3)+x+1)/((x^2)+1)^2;
f = integral(fun, 1,6);
Because you are using the matrix power operator (^) instead of the element-wise power operator (.^) in several places as well as the matrix division operator (/) rather than the element-wise (./) your function fails to satisfy the requirement that the fun input argument section of the documentation page for the integral function states it must.
"For scalar-valued problems, the function y = fun(x) must accept a vector argument, x, and return a vector result, y. This generally means that fun must use array operators instead of matrix operators. For example, use .* (times) rather than * (mtimes). If you set the 'ArrayValued' option to true, then fun must accept a scalar and return an array of fixed size."
Either use the element-wise (array) operators instead of the matrix operators (like Walter suggested) or set the 'ArrayValued' option to true as in the "Vector-Valued Function" example on that documentation page.

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by