Evaluate the explicit form of the Taylor polynomial of degree 2n-1 for arctan(x) with the point of approximation 0

1 view (last 30 days)
Write a Matlab code to evaluate the explicit form of the Taylor polynomial of degree 2n-1 for arctan(x) and the point of approximation 0.
So I tried to do this:
function value = polyeval(x, coeff);
n = length(coeff)
value = coeff(n)*taylor(arctan(x))
for i = n-1:-1:1
value = coeff(i) + x.*value;
end
But the teacher marked it as wrong. What would have been the correct way?

Accepted Answer

Walter Roberson
Walter Roberson on 10 Sep 2022
You tried to take the arctan of the polynomial degree, rather than the arctan of x.
In MATLAB, arctan is written as atan() or atan2()
MATLAB does not permit implicit multiplication, not anywhere . 2n is invalid MATLAB syntax in all cases: you need to supply a multiplication operator.
Example use of taylor:
syms x x0
f = sin(x).^2 - cos(x).^2
f = 
taylor(f, x, x0, 'order', 5)
ans = 
taylor(f, x, x0, 'order', 6)
ans = 
taylor(f, x, x0, 'order', 7)
ans = 
Your teacher expects you to figure out what the (2*n-1)'st term is of the taylor polynomial of arctan
  4 Comments
N/A
N/A on 11 Sep 2022
Edited: N/A on 11 Sep 2022
So then just this? I just get rid of the for loop?
x = 1;
y = 0;
y = y + (-1)^(i-1) * x^(2*i-1) / (2*i-1);

Sign in to comment.

More Answers (0)

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!