You are mixing symbolic math (syms
and sum
) with a numeric function to evaluate the integral (integarl
). While it is possible, it is typically not a good idea because you end up with the precision problems of a numeric solution and the bad performance of the symbolic math toolbox. If you want a numeric solution, do not use any function from the symbolic toolbox. If you want to solve it with the symbolic math toolbox, maybe getting a analytic result, use int
from the symbolic toolbox.
To explain what happened in your case. integral
evaluates your function for multiple y-values to calculate the integral, something like fun([0,.5,1])
. Your function calculates y^1.2 which is not possible, you want the element-wise operation in this case.
A further problem is, that the first y
you assign is unused. The y
in the next line where you define fun
is a new variable.
This answer does not contain a solution because I do not know if a symbolic or numeric solution is intended.
y
or yourfun
? – Adriaan