I need matlab code for cot(x) Taylor Polynomial Function
显示 更早的评论
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 个评论
John D'Errico
2019-3-25
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
2019-3-25
John D'Errico
2019-3-25
I explained the error in your code in my answer. It is in not understanding how to build that Taylor expansion.
采纳的回答
更多回答(1 个)
Torsten
2019-3-25
0 个投票
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))
类别
在 帮助中心 和 File Exchange 中查找有关 Number Theory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
