MATLAB: Error: The expression to the left of the equals sign is not a valid target for an assignment.

integration

I'm trying to integrate this rather nasty integral but i don't get a numerical answer
>> syms z >> int((25/4*(2*tan(z/2)*tan(z/2)-z*sec(z/2)*sec(z/2)*tan(z/2)+2)^2/(tan(z/2)*tan(z/2)+1)^3 + 25/4*(2*tan(z/2)*tan(z/2)*tan(z/2)+2*tan(z/2)+z*sec(z/2)*sec(z/2))^2/(tan(z/2)*tan(z/2)+1)^3 +1)^(1/2)*(z/sqrt(1+tan(z/2)*tan(z/2)))*100, 0,(20*pi))
ans =
int((100*z*((25*(2*tan(z/2)^2 – (z*tan(z/2))/cos(z/2)^2 + 2)^2)/(4*(tan(z/2)^2 + 1)^3) + (25*(2*tan(z/2) + z/cos(z/2)^2 + 2*tan(z/2)^3)^2)/(4*(tan(z/2)^2 + 1)^3) + 1)^(1/2))/(tan(z/2)^2 + 1)^(1/2), z, 0, 20*pi)
Why does it give me back the function and how do I integrate this function and get a numerical result?

Best Answer

If you want a numerical result, vectorize it and then use integral:
qz = vectorize('(25/4*(2*tan(z/2)*tan(z/2)-z*sec(z/2)*sec(z/2)*tan(z/2)+2)^2/(tan(z/2)*tan(z/2)+1)^3 + 25/4*(2*tan(z/2)*tan(z/2)*tan(z/2)+2*tan(z/2)+z*sec(z/2)*sec(z/2))^2/(tan(z/2)*tan(z/2)+1)^3 +1)^(1/2)*(z/sqrt(1+tan(z/2)*tan(z/2)))*100');
zfcn = str2func(['@(z) ' qz]);
zfcnint = integral(zfcn, 0,(20*pi))
zfcnint =
13192500.4786831
See the documentation on Vectorization (link) for details. I use the vectorize function here because I did not want to vectorize it manually.