MATLAB: Anonymous functions and integration

anonymous functionintegrationMATLAB

I want to integrate an anonymous function but be able to manipulate it first. For example
f = @(x) [x -x sin(x)];
r = integral (f'*f, 0, 1, 'ArrayValued', true);
This isn't possible. I would have to define a new function but this isn't flexible. Any alternatives to directly manipulate f?

Best Answer

Try
r = integral (@(x)f(x)'*f(x), 0, 1, 'ArrayValued', true);