matlab 泰勒函数逼近用matlab做x*sin(x)的泰勒级数

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/25 15:11:35
matlab泰勒函数逼近用matlab做x*sin(x)的泰勒级数matlab泰勒函数逼近用matlab做x*sin(x)的泰勒级数matlab泰勒函数逼近用matlab做x*sin(x)的泰勒级数c

matlab 泰勒函数逼近用matlab做x*sin(x)的泰勒级数
matlab 泰勒函数逼近
用matlab做x*sin(x)的泰勒级数

matlab 泰勒函数逼近用matlab做x*sin(x)的泰勒级数
close all
clear,clc
syms x;
f = x*sin(x);
t = taylor(f);
% 画x*sin(x)原函数
plotT = ezplot(f,[-3,3]);
set(plotT,'Color','red','LineWidth',4);
% 画x*sin(x)(n = 2 4 6 8)阶泰勒级数的曲线
NN = 3:2:9;
x1 = -3:0.01:3;
for I = 1:4
y = taylor(f,NN(I)); % degree n-1 functions
y1 = subs(y,x,x1);
PY(I,:) = y1(1,:); % degree n-1 functions
end
hold on;
plot(x1,PY','LineWidth',2);
xlabel('x')
ylabel('Tn(x)')
title('Taylor Series Expansion')
legend('sin(x)/x','n = 2','n = 4','n = 6','n = 8','Location','North')
grid on