Why I get wrong in integral function?

12 vues (au cours des 30 derniers jours)
JIANGWEN DONG
JIANGWEN DONG le 5 Fév 2021
fun = @(x) ((x.^3)+x+1)/((x^2)+1)^2;
f = integral(fun, 1,6);

Réponses (2)

Walter Roberson
Walter Roberson le 5 Fév 2021
fun = @(x) ((x.^3)+x+1)./((x.^2)+1).^2;

Steven Lord
Steven Lord le 5 Fév 2021
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.

Catégories

En savoir plus sur Numerical Integration and Differentiation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by