SlideShare ist ein Scribd-Unternehmen logo
1 von 4
第 9章 用 MATLAB 求二元泰勒展开式
 1 级数求和
    命令
    S=symsum(u,t,a,b)
                            b

的功能是计算级数和 S=               ∑ u 。其中 u 是包含符号变量 t 的表达式,是待求和级数的通项。当
                           t=a


u 的表达式中只含一个变量时,参数 t 可省略。
例 9.11.1 判断下列级数是否收敛,如收敛则求其和:
∞       ∞      ∞
     1      1      x2
∑ n , ∑ n2 , ∑ (1 + x 2 )n
n =1   n =1   n =0


解 创建符号变量 n 和 x,用 symsum 命令计算各级数的和:
  syms n x ↙
  symsum(1/n,1,inf) ↙
  ans=
   inf
         ∞
                1
知级数 ∑ 发散至无穷大。
     n   n =1


 symsum(1/n^2,1,inf) ↙
 ans=
  1/6*pi^2
         ∞
         1      π2
知级数 ∑ 2 收敛,且其和为
    n =1 n      6

          ∞
              x2
对级数 ∑            2 n ,由于其通项中包含两个变量 x 和 n,故使用 symsum 命令时须指定求
    n = 0 (1 + x )


和变量是 n:
un=x^2/(1+x^2)^n; ↙
symsun(un,n,0,inf) ↙
ans=
 1+x^2
得和函数为 1+x^2
  对有些级数, symsum 命令不能求得其和,从而也无法得知其敛散性。此时,可使用
MATLAB 的数值计算功能进行处理。
                    ∞
                                 1
例 9.11.2 试求级数 ∑ ln(1 +           2
                                     ) 的和
                       n
                    n =1


解     用 symsum 命令求解:
     syms n ↙
     symsum(log(1+1/n^2),1,inf) ↙
ans=
  sum(log(1+1/n^2),n=1..inf)
此 结 果 表 示 symsum 命 令 不 能 求 得 其 和 。 我 们 转 而 采 用 数 值 方 法 计 算 部 分 和
      n
                     1
S n = ∑ ln(1 +          )           m
     k =1            k 2 。将下面的程序存入一个 文件中:

 clear all
 n=9000; %部分和的项数
 Sn=0;
 for k=1:n
   Sn= Sn+log(1+1/k^2);
 end
 fprintf(‘Sn=%f,(n=%d)’, Sn,n)
执行该程序,显示结果为
  Sn=1.301735,(n=9000)
再对程序中的变量 n 分别赋值 n=9000 ,n=900000 ,n=9000000 并执行程序,得计算结果为:
  Sn=1.301835,( n=9000 )
  Sn=1.301845,( n=900000)
  Sn=1.301846,( n=9000000)
由此看出,随着 n 增大,Sn 趋于 1.30185。故知该级数收敛,且其和约为 1.30185
2.泰勒级数展开
泰勒级数展开命令是 taylor,其调用格式为
       r=taylor(f,n,x,a).
该命令的功能是将符号函数 f 展开成(x-a)的 n-1 阶泰勒多项式。其中 x 是待展开的符号变
量,其缺省值为最接近 x 的字母。n 的缺省值为 n=6,a 的缺省值为 a=0。
                     x
例 9.11.3 将                   分别展开为 x 和 x-1 的幂级数。
                    1 + x2

解 首先创建符号变量 x 及函数 f:
  syms x ↙
  f=x/sqrt(1+x^2); ↙
计算关于 x 展式的前 8 项:
  taylor(f,8)
  ans=
  x-1/2*x^3+3/8*x^5-5/16*x^7
计算关于 x-1 展式的前 3 项:
  taylor(f,3,x,1) ↙
  ans=
  1/2*2^(1/2)+1/4*2^(1/2)*(x-1)-16/3*2^(1/2)*(x-1)/2
     x                2    2            3 2
即               =       +    ( x − 1) −     ( x − 1) 2 + ... 。
    1+ x    2        2    4              16


3.傅里叶级数展开
到目前为止,MATLAB 中还没有专门计算傅里叶展开式的命令。但根据尤拉-傅里叶公式,
用 int 命令很容易算出傅里叶级数的系数:
 syms n x
 a0=int(f,-pi,pi)/pi
 an= int(f*cos(n*x),-pi,pi)/pi
 bn=int(f*sin(n*x),-pi,pi)/pi
其中 f 为含符号变量 x 的待展开函数。
 类似可得,对周期为 2l 的函数,计算其傅里叶系数的命令为
   a0=int(f,-l,l)/l
    an= int(f*cos(n*pi*x/l),-l,l)/l
    bn=int(f*sin(n*pi*x/l),-l,l)/l.
                                0, −2 ≤ x < 0,
例 9.11.4 用 MATLAB 求 f ( x) = k , 0 ≤ x < 2, (常数k ≠ 0) 的傅里叶展开式。
                             
解
syms k n x ↙
a0=int(k,x,0,2) ↙
a0=
k
an=int(k*cos(n*pi*x/2),x,0,2)/2 ↙
an=
sin(n*pi)*k/n/pi
bn= int(k*sin (n*pi*x/2),x,0,2)/2 ↙
bn=
-k*(cos(n*pi)-1)/n/pi
                                                         n
注意 MATLAB 不能把 sin(n*pi)化为 0,也不能把 cos(n*pi)化为(-1)

例 9.11.5 本例中的程序演示了用正弦波迭加逼近方波的过程。取例 9.11.4 中所得傅里叶级数

的前 m 项作和,记为 S m 这是 m 个正弦波的合成波。执行下面程序可观察到,随着 m 逐渐

增大, S m 的波形逐渐逼近 f(x)(周期性延拓后)的波形,图 1 与图 2 分别是该程序执行中

当 m=3 和 m=6 时的快照
 m = 40;
   k = 1;
   syms x
   hold on
   Sm = k/2;
   for n = 1:m
     fn = 2*k*sin((2*n-1)*pi*x/2)/(2*n-1)/pi;
     Sm = Sm + fn;
     clf
     subplot(2,1,1)
     ezplot(fn,[-6,6])
subplot(2,1,2)
  ezplot(Sm,[-6,6])
  if n<6
     pause
  else
     pause(5/n)
  end
end
                      图1




                           图2

Weitere ähnliche Inhalte

Was ist angesagt?

Modeling and Simulation of Solar Photovoltaic System
Modeling and Simulation of Solar Photovoltaic SystemModeling and Simulation of Solar Photovoltaic System
Modeling and Simulation of Solar Photovoltaic System
ijtsrd
 
Tidal power plants
Tidal power plantsTidal power plants
Tidal power plants
tonygracious
 
Renewable energy & its furure prospects in india
Renewable energy & its furure prospects in indiaRenewable energy & its furure prospects in india
Renewable energy & its furure prospects in india
Surabhi Pal
 
значење на електричната енергија
значење на електричната енергијазначење на електричната енергија
значење на електричната енергија
Jovanka Ivanova
 

Was ist angesagt? (20)

Pgfs document
Pgfs documentPgfs document
Pgfs document
 
Hybrid Energy Systems
Hybrid Energy Systems Hybrid Energy Systems
Hybrid Energy Systems
 
Tidal Energy ppt
Tidal Energy pptTidal Energy ppt
Tidal Energy ppt
 
Introduction to Wind Energy
Introduction to Wind EnergyIntroduction to Wind Energy
Introduction to Wind Energy
 
CH-2_PPEE.ppt
CH-2_PPEE.pptCH-2_PPEE.ppt
CH-2_PPEE.ppt
 
Solar PV Codes and Standards
Solar PV Codes and StandardsSolar PV Codes and Standards
Solar PV Codes and Standards
 
Modeling and Simulation of Solar Photovoltaic System
Modeling and Simulation of Solar Photovoltaic SystemModeling and Simulation of Solar Photovoltaic System
Modeling and Simulation of Solar Photovoltaic System
 
FACTS DEVICES AND POWER SYSTEM STABILITY ppt
FACTS DEVICES AND POWER SYSTEM STABILITY pptFACTS DEVICES AND POWER SYSTEM STABILITY ppt
FACTS DEVICES AND POWER SYSTEM STABILITY ppt
 
Three phase transformer ( vector groups)
Three phase  transformer ( vector groups)Three phase  transformer ( vector groups)
Three phase transformer ( vector groups)
 
Wind Power Generation Schemes
Wind Power Generation SchemesWind Power Generation Schemes
Wind Power Generation Schemes
 
pumped hydro energy storage system
pumped hydro energy storage systempumped hydro energy storage system
pumped hydro energy storage system
 
Tidal power plants
Tidal power plantsTidal power plants
Tidal power plants
 
Tidal energy technology
Tidal energy technologyTidal energy technology
Tidal energy technology
 
Renewable energy & its furure prospects in india
Renewable energy & its furure prospects in indiaRenewable energy & its furure prospects in india
Renewable energy & its furure prospects in india
 
Unit commitment
Unit commitmentUnit commitment
Unit commitment
 
Wind Turbine
Wind TurbineWind Turbine
Wind Turbine
 
Solar panel i v characteristics
Solar panel i v characteristicsSolar panel i v characteristics
Solar panel i v characteristics
 
Pv solar plant components
Pv solar plant componentsPv solar plant components
Pv solar plant components
 
Splar pv
Splar pvSplar pv
Splar pv
 
значење на електричната енергија
значење на електричната енергијазначење на електричната енергија
значење на електричната енергија
 

Ähnlich wie 09.第九章用Matlab求二元泰勒展开式

11.第十一章用Matlab计算多元函数的积分
11.第十一章用Matlab计算多元函数的积分11.第十一章用Matlab计算多元函数的积分
11.第十一章用Matlab计算多元函数的积分
Xin Zheng
 
Algorithms.exercises.solution
Algorithms.exercises.solutionAlgorithms.exercises.solution
Algorithms.exercises.solution
Regina Long
 
02.第二章用Matlab求导
02.第二章用Matlab求导02.第二章用Matlab求导
02.第二章用Matlab求导
Xin Zheng
 
第3章 离散系统的时域分析
第3章   离散系统的时域分析第3章   离散系统的时域分析
第3章 离散系统的时域分析
reader520
 
241525第三章初等代数运算命令与例题
241525第三章初等代数运算命令与例题241525第三章初等代数运算命令与例题
241525第三章初等代数运算命令与例题
gwadhysys
 
06.第六章用Matlab计算二重积分
06.第六章用Matlab计算二重积分06.第六章用Matlab计算二重积分
06.第六章用Matlab计算二重积分
Xin Zheng
 
实验一 Mathematica软件简介
实验一   Mathematica软件简介实验一   Mathematica软件简介
实验一 Mathematica软件简介
guestfe33f0e
 
实验一 Mathematica软件简介
实验一   Mathematica软件简介实验一   Mathematica软件简介
实验一 Mathematica软件简介
Xin Zheng
 
[ACM-ICPC] Efficient Algorithm
[ACM-ICPC] Efficient Algorithm[ACM-ICPC] Efficient Algorithm
[ACM-ICPC] Efficient Algorithm
Chih-Hsuan Kuo
 
实验六 用Mathematica软件进行 级数运算
实验六  用Mathematica软件进行 级数运算实验六  用Mathematica软件进行 级数运算
实验六 用Mathematica软件进行 级数运算
guestfe33f0e
 
实验六 用Mathematica软件进行 级数运算
实验六  用Mathematica软件进行 级数运算实验六  用Mathematica软件进行 级数运算
实验六 用Mathematica软件进行 级数运算
Xin Zheng
 
Lambda演算与邱奇编码
Lambda演算与邱奇编码Lambda演算与邱奇编码
Lambda演算与邱奇编码
Qin Jian
 

Ähnlich wie 09.第九章用Matlab求二元泰勒展开式 (20)

11.第十一章用Matlab计算多元函数的积分
11.第十一章用Matlab计算多元函数的积分11.第十一章用Matlab计算多元函数的积分
11.第十一章用Matlab计算多元函数的积分
 
Algorithms.exercises.solution
Algorithms.exercises.solutionAlgorithms.exercises.solution
Algorithms.exercises.solution
 
02.第二章用Matlab求导
02.第二章用Matlab求导02.第二章用Matlab求导
02.第二章用Matlab求导
 
第3章 离散系统的时域分析
第3章   离散系统的时域分析第3章   离散系统的时域分析
第3章 离散系统的时域分析
 
Ihome inaction 篇外篇之fp介绍
Ihome inaction 篇外篇之fp介绍Ihome inaction 篇外篇之fp介绍
Ihome inaction 篇外篇之fp介绍
 
第2章符 号 运 算
第2章符 号 运 算第2章符 号 运 算
第2章符 号 运 算
 
Ch11 範例
Ch11 範例Ch11 範例
Ch11 範例
 
Ch5 範例
Ch5 範例Ch5 範例
Ch5 範例
 
241525第三章初等代数运算命令与例题
241525第三章初等代数运算命令与例题241525第三章初等代数运算命令与例题
241525第三章初等代数运算命令与例题
 
06.第六章用Matlab计算二重积分
06.第六章用Matlab计算二重积分06.第六章用Matlab计算二重积分
06.第六章用Matlab计算二重积分
 
实验一 Mathematica软件简介
实验一   Mathematica软件简介实验一   Mathematica软件简介
实验一 Mathematica软件简介
 
实验一 Mathematica软件简介
实验一   Mathematica软件简介实验一   Mathematica软件简介
实验一 Mathematica软件简介
 
福建省福州大学2019年暑假物理竞赛夏令营-物理奥赛进阶之路:0-1+微积分初步+40张ppt.pptx
福建省福州大学2019年暑假物理竞赛夏令营-物理奥赛进阶之路:0-1+微积分初步+40张ppt.pptx福建省福州大学2019年暑假物理竞赛夏令营-物理奥赛进阶之路:0-1+微积分初步+40张ppt.pptx
福建省福州大学2019年暑假物理竞赛夏令营-物理奥赛进阶之路:0-1+微积分初步+40张ppt.pptx
 
指考甲公式
指考甲公式指考甲公式
指考甲公式
 
Ch2
Ch2Ch2
Ch2
 
[ACM-ICPC] Efficient Algorithm
[ACM-ICPC] Efficient Algorithm[ACM-ICPC] Efficient Algorithm
[ACM-ICPC] Efficient Algorithm
 
实验六 用Mathematica软件进行 级数运算
实验六  用Mathematica软件进行 级数运算实验六  用Mathematica软件进行 级数运算
实验六 用Mathematica软件进行 级数运算
 
实验六 用Mathematica软件进行 级数运算
实验六  用Mathematica软件进行 级数运算实验六  用Mathematica软件进行 级数运算
实验六 用Mathematica软件进行 级数运算
 
南开大学暑期ACM集训
南开大学暑期ACM集训南开大学暑期ACM集训
南开大学暑期ACM集训
 
Lambda演算与邱奇编码
Lambda演算与邱奇编码Lambda演算与邱奇编码
Lambda演算与邱奇编码
 

Mehr von Xin Zheng

Humidity and temperature
Humidity and temperatureHumidity and temperature
Humidity and temperature
Xin Zheng
 
Humidity and temperature
Humidity and temperatureHumidity and temperature
Humidity and temperature
Xin Zheng
 
Release coats presentation-pstc
Release coats presentation-pstcRelease coats presentation-pstc
Release coats presentation-pstc
Xin Zheng
 
Release coating special additive product selection guide
Release coating special additive product selection guideRelease coating special additive product selection guide
Release coating special additive product selection guide
Xin Zheng
 
05.第五章用Matlab计算积分
05.第五章用Matlab计算积分05.第五章用Matlab计算积分
05.第五章用Matlab计算积分
Xin Zheng
 
12.第十二章用Matlab计算第二类积分
12.第十二章用Matlab计算第二类积分12.第十二章用Matlab计算第二类积分
12.第十二章用Matlab计算第二类积分
Xin Zheng
 
10.第十章用Matlab画空间曲线
10.第十章用Matlab画空间曲线10.第十章用Matlab画空间曲线
10.第十章用Matlab画空间曲线
Xin Zheng
 
08.第八章用Matlab求二元泰勒展开式
08.第八章用Matlab求二元泰勒展开式08.第八章用Matlab求二元泰勒展开式
08.第八章用Matlab求二元泰勒展开式
Xin Zheng
 
07.第七章用Matlab解常微分方程
07.第七章用Matlab解常微分方程07.第七章用Matlab解常微分方程
07.第七章用Matlab解常微分方程
Xin Zheng
 
03.第三章用Matlab求极值
03.第三章用Matlab求极值03.第三章用Matlab求极值
03.第三章用Matlab求极值
Xin Zheng
 
04.第四章用Matlab求偏导数
04.第四章用Matlab求偏导数04.第四章用Matlab求偏导数
04.第四章用Matlab求偏导数
Xin Zheng
 
01.第一章用Matlab求极限
01.第一章用Matlab求极限01.第一章用Matlab求极限
01.第一章用Matlab求极限
Xin Zheng
 
实验十 用Mathematica计算重积分
实验十  用Mathematica计算重积分实验十  用Mathematica计算重积分
实验十 用Mathematica计算重积分
Xin Zheng
 
实验五 用Mathematica软件计算一元函数的积分
实验五  用Mathematica软件计算一元函数的积分实验五  用Mathematica软件计算一元函数的积分
实验五 用Mathematica软件计算一元函数的积分
Xin Zheng
 
实验四 用Mathematica软件作导数应用
实验四  用Mathematica软件作导数应用实验四  用Mathematica软件作导数应用
实验四 用Mathematica软件作导数应用
Xin Zheng
 
实验三 用Mathematica软件计算导数与微分
实验三  用Mathematica软件计算导数与微分实验三  用Mathematica软件计算导数与微分
实验三 用Mathematica软件计算导数与微分
Xin Zheng
 
实验七 用Mathematica解常微分方程
实验七  用Mathematica解常微分方程实验七  用Mathematica解常微分方程
实验七 用Mathematica解常微分方程
Xin Zheng
 
实验二 用Mathmatica软件求极限
实验二  用Mathmatica软件求极限实验二  用Mathmatica软件求极限
实验二 用Mathmatica软件求极限
Xin Zheng
 
实验九 用Mathematica软件求函数偏导数与多元函数的极值
实验九  用Mathematica软件求函数偏导数与多元函数的极值实验九  用Mathematica软件求函数偏导数与多元函数的极值
实验九 用Mathematica软件求函数偏导数与多元函数的极值
Xin Zheng
 
实验八 用Mathematica进行向量运算及曲面绘制
实验八  用Mathematica进行向量运算及曲面绘制实验八  用Mathematica进行向量运算及曲面绘制
实验八 用Mathematica进行向量运算及曲面绘制
Xin Zheng
 

Mehr von Xin Zheng (20)

Humidity and temperature
Humidity and temperatureHumidity and temperature
Humidity and temperature
 
Humidity and temperature
Humidity and temperatureHumidity and temperature
Humidity and temperature
 
Release coats presentation-pstc
Release coats presentation-pstcRelease coats presentation-pstc
Release coats presentation-pstc
 
Release coating special additive product selection guide
Release coating special additive product selection guideRelease coating special additive product selection guide
Release coating special additive product selection guide
 
05.第五章用Matlab计算积分
05.第五章用Matlab计算积分05.第五章用Matlab计算积分
05.第五章用Matlab计算积分
 
12.第十二章用Matlab计算第二类积分
12.第十二章用Matlab计算第二类积分12.第十二章用Matlab计算第二类积分
12.第十二章用Matlab计算第二类积分
 
10.第十章用Matlab画空间曲线
10.第十章用Matlab画空间曲线10.第十章用Matlab画空间曲线
10.第十章用Matlab画空间曲线
 
08.第八章用Matlab求二元泰勒展开式
08.第八章用Matlab求二元泰勒展开式08.第八章用Matlab求二元泰勒展开式
08.第八章用Matlab求二元泰勒展开式
 
07.第七章用Matlab解常微分方程
07.第七章用Matlab解常微分方程07.第七章用Matlab解常微分方程
07.第七章用Matlab解常微分方程
 
03.第三章用Matlab求极值
03.第三章用Matlab求极值03.第三章用Matlab求极值
03.第三章用Matlab求极值
 
04.第四章用Matlab求偏导数
04.第四章用Matlab求偏导数04.第四章用Matlab求偏导数
04.第四章用Matlab求偏导数
 
01.第一章用Matlab求极限
01.第一章用Matlab求极限01.第一章用Matlab求极限
01.第一章用Matlab求极限
 
实验十 用Mathematica计算重积分
实验十  用Mathematica计算重积分实验十  用Mathematica计算重积分
实验十 用Mathematica计算重积分
 
实验五 用Mathematica软件计算一元函数的积分
实验五  用Mathematica软件计算一元函数的积分实验五  用Mathematica软件计算一元函数的积分
实验五 用Mathematica软件计算一元函数的积分
 
实验四 用Mathematica软件作导数应用
实验四  用Mathematica软件作导数应用实验四  用Mathematica软件作导数应用
实验四 用Mathematica软件作导数应用
 
实验三 用Mathematica软件计算导数与微分
实验三  用Mathematica软件计算导数与微分实验三  用Mathematica软件计算导数与微分
实验三 用Mathematica软件计算导数与微分
 
实验七 用Mathematica解常微分方程
实验七  用Mathematica解常微分方程实验七  用Mathematica解常微分方程
实验七 用Mathematica解常微分方程
 
实验二 用Mathmatica软件求极限
实验二  用Mathmatica软件求极限实验二  用Mathmatica软件求极限
实验二 用Mathmatica软件求极限
 
实验九 用Mathematica软件求函数偏导数与多元函数的极值
实验九  用Mathematica软件求函数偏导数与多元函数的极值实验九  用Mathematica软件求函数偏导数与多元函数的极值
实验九 用Mathematica软件求函数偏导数与多元函数的极值
 
实验八 用Mathematica进行向量运算及曲面绘制
实验八  用Mathematica进行向量运算及曲面绘制实验八  用Mathematica进行向量运算及曲面绘制
实验八 用Mathematica进行向量运算及曲面绘制
 

09.第九章用Matlab求二元泰勒展开式

  • 1. 第 9章 用 MATLAB 求二元泰勒展开式 1 级数求和 命令 S=symsum(u,t,a,b) b 的功能是计算级数和 S= ∑ u 。其中 u 是包含符号变量 t 的表达式,是待求和级数的通项。当 t=a u 的表达式中只含一个变量时,参数 t 可省略。 例 9.11.1 判断下列级数是否收敛,如收敛则求其和: ∞ ∞ ∞ 1 1 x2 ∑ n , ∑ n2 , ∑ (1 + x 2 )n n =1 n =1 n =0 解 创建符号变量 n 和 x,用 symsum 命令计算各级数的和: syms n x ↙ symsum(1/n,1,inf) ↙ ans= inf ∞ 1 知级数 ∑ 发散至无穷大。 n n =1 symsum(1/n^2,1,inf) ↙ ans= 1/6*pi^2 ∞ 1 π2 知级数 ∑ 2 收敛,且其和为 n =1 n 6 ∞ x2 对级数 ∑ 2 n ,由于其通项中包含两个变量 x 和 n,故使用 symsum 命令时须指定求 n = 0 (1 + x ) 和变量是 n: un=x^2/(1+x^2)^n; ↙ symsun(un,n,0,inf) ↙ ans= 1+x^2 得和函数为 1+x^2 对有些级数, symsum 命令不能求得其和,从而也无法得知其敛散性。此时,可使用 MATLAB 的数值计算功能进行处理。 ∞ 1 例 9.11.2 试求级数 ∑ ln(1 + 2 ) 的和 n n =1 解 用 symsum 命令求解: syms n ↙ symsum(log(1+1/n^2),1,inf) ↙
  • 2. ans= sum(log(1+1/n^2),n=1..inf) 此 结 果 表 示 symsum 命 令 不 能 求 得 其 和 。 我 们 转 而 采 用 数 值 方 法 计 算 部 分 和 n 1 S n = ∑ ln(1 + ) m k =1 k 2 。将下面的程序存入一个 文件中: clear all n=9000; %部分和的项数 Sn=0; for k=1:n Sn= Sn+log(1+1/k^2); end fprintf(‘Sn=%f,(n=%d)’, Sn,n) 执行该程序,显示结果为 Sn=1.301735,(n=9000) 再对程序中的变量 n 分别赋值 n=9000 ,n=900000 ,n=9000000 并执行程序,得计算结果为: Sn=1.301835,( n=9000 ) Sn=1.301845,( n=900000) Sn=1.301846,( n=9000000) 由此看出,随着 n 增大,Sn 趋于 1.30185。故知该级数收敛,且其和约为 1.30185 2.泰勒级数展开 泰勒级数展开命令是 taylor,其调用格式为 r=taylor(f,n,x,a). 该命令的功能是将符号函数 f 展开成(x-a)的 n-1 阶泰勒多项式。其中 x 是待展开的符号变 量,其缺省值为最接近 x 的字母。n 的缺省值为 n=6,a 的缺省值为 a=0。 x 例 9.11.3 将 分别展开为 x 和 x-1 的幂级数。 1 + x2 解 首先创建符号变量 x 及函数 f: syms x ↙ f=x/sqrt(1+x^2); ↙ 计算关于 x 展式的前 8 项: taylor(f,8) ans= x-1/2*x^3+3/8*x^5-5/16*x^7 计算关于 x-1 展式的前 3 项: taylor(f,3,x,1) ↙ ans= 1/2*2^(1/2)+1/4*2^(1/2)*(x-1)-16/3*2^(1/2)*(x-1)/2 x 2 2 3 2 即 = + ( x − 1) − ( x − 1) 2 + ... 。 1+ x 2 2 4 16 3.傅里叶级数展开
  • 3. 到目前为止,MATLAB 中还没有专门计算傅里叶展开式的命令。但根据尤拉-傅里叶公式, 用 int 命令很容易算出傅里叶级数的系数: syms n x a0=int(f,-pi,pi)/pi an= int(f*cos(n*x),-pi,pi)/pi bn=int(f*sin(n*x),-pi,pi)/pi 其中 f 为含符号变量 x 的待展开函数。 类似可得,对周期为 2l 的函数,计算其傅里叶系数的命令为 a0=int(f,-l,l)/l an= int(f*cos(n*pi*x/l),-l,l)/l bn=int(f*sin(n*pi*x/l),-l,l)/l. 0, −2 ≤ x < 0, 例 9.11.4 用 MATLAB 求 f ( x) = k , 0 ≤ x < 2, (常数k ≠ 0) 的傅里叶展开式。  解 syms k n x ↙ a0=int(k,x,0,2) ↙ a0= k an=int(k*cos(n*pi*x/2),x,0,2)/2 ↙ an= sin(n*pi)*k/n/pi bn= int(k*sin (n*pi*x/2),x,0,2)/2 ↙ bn= -k*(cos(n*pi)-1)/n/pi n 注意 MATLAB 不能把 sin(n*pi)化为 0,也不能把 cos(n*pi)化为(-1) 例 9.11.5 本例中的程序演示了用正弦波迭加逼近方波的过程。取例 9.11.4 中所得傅里叶级数 的前 m 项作和,记为 S m 这是 m 个正弦波的合成波。执行下面程序可观察到,随着 m 逐渐 增大, S m 的波形逐渐逼近 f(x)(周期性延拓后)的波形,图 1 与图 2 分别是该程序执行中 当 m=3 和 m=6 时的快照 m = 40; k = 1; syms x hold on Sm = k/2; for n = 1:m fn = 2*k*sin((2*n-1)*pi*x/2)/(2*n-1)/pi; Sm = Sm + fn; clf subplot(2,1,1) ezplot(fn,[-6,6])
  • 4. subplot(2,1,2) ezplot(Sm,[-6,6]) if n<6 pause else pause(5/n) end end 图1 图2