I need matlab code for cot(x) Taylor Polynomial Function
Show older comments
For x in range [pi/8 , 7pi/8] and f(x)=cot(x) I need to plot Taylor Polynomial P0(x),P1(x) and P2(x) of f about the base point x=a=5pi/8. increment step size must be 0.01
I cannot write the code, I tried something with writing the differentation manuel but when I plot the graph P0, P2 didnt gave me anything.
Also xmin=0.1 xmax=3 and ymin=-2,5 ymax=2.5
Thanks for helping.
clc
clear all
close all
syms x
x = pi/8 : 0.01: 7*pi/8;
f = cot(x);
a = 5*pi/8;
P0=cot(a);
P1=cot(a)+(- cot(a).^2 - 1).*(x-a);
P2=cot(a)+(- cot(a).^2 - 1).*(x-a)+(2.*cot(a).*(cot(a).^2 + 1))/factorial(2).*((x-a).^2);
P3=cot(a)+(- cot(a).^2 - 1).*(x-a)+(2.*cot(a).*(cot(a).^2 + 1))/factorial(2).*((x-a).^2)+(- 4.*cot(a).^2.*(cot(a).^2 + 1) - 2.*(cot(a).^2 + 1).^2)/factorial(3).*((x-a).^3);
xlabel('x axis')
ylabel ('y axis')
xlim([0.1 3])
ylim([-2.5 2.5])
grid on
3 Comments
John D'Errico
on 25 Mar 2019
Let me see if I understand this. You are writing a Taylor series for cot(x), expaded around a point a. In that series, you use the function cot(x). Can you see the fundamental problem in what you have done?
hgrlk
on 25 Mar 2019
John D'Errico
on 25 Mar 2019
I explained the error in your code in my answer. It is in not understanding how to build that Taylor expansion.
Accepted Answer
More Answers (1)
Torsten
on 25 Mar 2019
0 votes
f = @(x)cot(x);
a = 5*pi/8;
P0 = @(x)f(a)*ones(size(x));
P1 = @(x)f(a)+(- f(a).^2 - 1).*(x-a);
P2 = @(x) f(a)+(- f(a).^2 - 1).*(x-a)+(2.*f(a).*(f(a).^2 + 1))/factorial(2).*((x-a).^2);
P3 = @(x)f(a)+(- f(a).^2 - 1).*(x-a)+(2.*f(a).*(f(a).^2 + 1))/factorial(2).*((x-a).^2)+(- 4.*f(a).^2.*(f(a).^2 + 1) - 2.*(f(a).^2 + 1).^2)/factorial(3).*((x-a).^3);
x = pi/8:0.01:7*pi/8;
plot(x,P3(x),x,cot(x))
Categories
Find more on Number Theory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!