The first error indicates that the matrix dimensions do not agree. This is because the INTEGRAL command passes the value of "x" into the function argument as a vector. However, since the "^" operator tries to square this vector, the matrix dimensionality error occurs. This is same as trying:
For divisions, the vectors involved in the division undergo matrix division and yield a scalar. However, the output that is expected by INTEGRAL is a vector. Therefore, although there is no error when calculating the division, an error occurs while evaluating the integral.
To work around these issues, please use element-wise math operators in the function definition. The correct commands would be:
integral(@(x) x.^2,0,100)
integral(@(x) x./2,0,100)
Best Answer