MATLAB: What’s wrong with this integral

integral

I get an error message typing this:
integral(@(z)(sin(z)*exp(1i*z)),0, 1)
Here is the error message:
Error using *
Inner matrix dimensions must agree.
Error in @(z)(sin(z)*exp(1i*z))
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);

Best Answer

You likely need to vectorise it:
integral(@(z)(sin(z).*exp(1i*z)),0, 1)
Note the vectorised multiplication (.*). See Array vs. Matrix Operations for a full discussion.