MATLAB: Taylor series in Matlab

MATLABtaylor series

I am taking a MATLAB class and the instructions given to run a taylor series example test run is not working:
To get the Taylor Polynomial of Degree 5:
>> syms f x p5
>> f=log(1+x)
>> p5=taylor(f,6)
p5 = x - 1/2*x^2 + 1/3*x^3 - 1/4*x^4 + 1/5*x^5 % p5 is shorthand for P5(x)
This is the example code is gives me to test, but when I try to use it, it returns this error code:
Error using sym/taylor (line 99)
The value of 'x' is invalid. It must satisfy the function:
@(x)isvector(x)&&isAllVars(x).
What is the correct instruction to get this example to work?

Best Answer

p5 = taylor(f, 'Order', 6)