I need matlab code for cot(x) Taylor Polynomial Function
Mostra commenti meno recenti
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 Commenti
John D'Errico
il 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
il 25 Mar 2019
John D'Errico
il 25 Mar 2019
I explained the error in your code in my answer. It is in not understanding how to build that Taylor expansion.
Risposta accettata
Più risposte (1)
Torsten
il 25 Mar 2019
0 voti
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))
Categorie
Scopri di più su Number Theory in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
