We want to plot f(x) and Taylor polynomials P0(x), P1(x),P2(x), P3(x) of f(x)=cot(x) ; about base point x=a=5*pi/8. step size is 0.01
The problem is we can't make our Taylor Series sum( T1) work. It gives this error:
Error using diff
Difference order N must be a positive integer scalar.
Error in matlab_hw1_q3 (line 11)
T1=sum( (diff(f(a),n(1,i))) ./ factorial(n(1,i)) .* ((x-a).^n(1,i)) , n(1,i))
Our code:
clc clear allclose allf=@(x) cot(x)x= pi/8:0.01:7*pi/8 ;a=5*pi/8 ;n=[0 1 2 3]for i=1:1:4T1=sum( (diff(f(a),n(1,i))) ./ factorial(n(1,i)) .* ((x-a).^n(1,i)) , n(1,i))end
Best Answer