MATLAB: Incorrect Matlab form

cosineequation

Im trying to write the equation f(x) = e^x + 2^-x +2cosx-6 in matlab code. I've tried the following and it gives me an error that points to cos.
f=@(x) exp(x)+2^(-x)+2cos(x)-6 gives Error: Unexpected MATLAB expression that points to cosx

Best Answer

You need a star (multiplication symbol) after the 2:
f=@(x) exp(x) + 2.^(-x) + 2*cos(x) - 6
Related Question