早教吧 育儿知识 作业答案 考试题库 百科 知识分享

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
看了 matlab 泰勒函数逼近用...的网友还看了以下: