MATLAB: Atan Taylor Polynomial using polyval function.

atan(x)polyvaltaylor polynomial

I need to write a function that computes the Taylor polynomial P_n(x) for a general odd number n>=1 using the built-in Matlab function polyval. I have the following function so far for the Taylor polynomial:
[ y ] = ost_arctanTaylor(n, x)
%Computes the Taylor polynomial for f(x) = atan(x)
for i = 1:2:n
y = ((-1).^(i)).*((x.^(2.*i-1))./(2.*i-1));
end
end
I am confused on how to integrate the polyval function into this code. Any help?

Best Answer

You are trying to evaluate the polynomial itself in a loop, although the loop as you wrote it will not do what you think.
The requirement was for polyval to evaluate it, NOT you. So you need to build the coefficients of the polynomial, and pass them into polyval. Let it do the work.