Why I get wrong in integral function?
조회 수: 2 (최근 30일)
이전 댓글 표시
fun = @(x) ((x.^3)+x+1)/((x^2)+1)^2;
f = integral(fun, 1,6);
댓글 수: 0
답변 (2개)
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.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!