MATLAB: Call specific expression index from a function carrying multiple expression

arrayfunction

I had defined a function
function y=func (x)
y=[x;x.^2];
Now I have to integrate each expression i.e. x and x^2 for different limits. Eg. quad('x',1,5) and quad('x^2',5,9)..How can we do this using the function as defined earlier?

Best Answer

Break it up in to two different integrations with different functions and add the two results together.
You can use helper functions such as
row1 = @(x) x(1,:);
row2 = @(x) x(2,:);
quad(@(x) row1(f(x)), 1, 5) + quad(@(x) row2(f(x)), 5, 9)