实验四MATLAB求Laplace变换及逆变换(一)实验类型:设计性(二)实验类别:基础实验(三) 实验学时数:2学时(四)实验目的1、掌握MATLAB符号计算,符号对象,符号微积分,符号方程求解;2、熟悉MATLAB的Laplace逆变换;3、设计用积分变换解答微分方程(五)实验内容MATLAB基本命令与实际操作、设计微分方程的解答文件(六)实验要求1、学生在实验操作过程中自己动手独立完成,1人为1组。2、完成实验报告:按照试验的每个题目的具体要求完成(七)实验仪器、设备计算机(安装Windows98、Windows2000或WindowsXP或以上)(八)实验课承担单位:数学实验室主要练习和使用laplace0、ilaplace0等命令。1、LAPLACE命令.L=LAPLACE(F)将一个自变量为t的函数转变成它的LAPLACE变换.如果 F=F(s),那么该命令得到一个自变量为t的函数:L=L(t)该函数是通过命令L(s)=int(F(t)*exp(-s*t),0,inf)得到的。1
1 实验四 MATLAB 求 Laplace 变换及逆变换 (一) 实验类型:设计性 (二) 实验类别:基础实验 (三) 实验学时数:2 学时 (四) 实验目的 1、掌握 MATLAB 符号计算,符号对象,符号微积分,符号方程求解; 2、熟悉 MATLAB 的 Laplace 逆变换; 3、设计用积分变换解答微分方程. (五) 实验内容 MATLAB 基本命令与实际操作、设计微分方程的解答文件 (六) 实验要求 1、学生在实验操作过程中自己动手独立完成,1 人为 1 组。 2、完成实验报告:按照试验的每个题目的具体要求完成 (七) 实验仪器、设备 计算机(安装 Windows98 、Windows2000 或 Windows XP 或以 上) (八) 实验课承担单位:数学实验室 主要练习和使用 laplace()、ilaplace()等命令。 1、LAPLACE 命令. L = LAPLACE(F) 将一个自变量为 t 的函数转变成它的 LAPLACE 变换. 如 果 F = F(s), 那么该命令得到一个自变量为 t 的函数: L = L(t). 该函数是通过命令 L(s) = int(F(t)*exp(-s*t),0,inf)得到的
L=LAPLACE(F,t)使自变量用t替换LAPLACE(F,t)等价于 L(t) = int(F(x)*exp(-t*x),O,inf)L=LAPLACE(F,W,z)在变换中使z取代sLAPLACE(F,W,z)等价于 L(z)= int(F(w)*exp(-z*w),0,inf)Examplessymsastwx120/s^6laplace(t^5)returns1/(t-a)laplace(exp(a*s)returnsw/(t^2+w^2)laplace(sin(w*x),t)returnslaplace(cos(x*w),w,t)returnst/(t^2+×^2)5laplace(x^sym(3/2),t) returns3/4*piα(1/2)/t^(5/2)laplace(diff(sym('F(t)returnslaplace(F(t),t,s)*s-F(O)2、ILAPLACE是laplace逆变换命令.F=ILAPLACE(L)将自变量为s的函数L转换成原像得到一个自变量为t的函数。如果L=L(t),那么ILAPLACE返回一个自变量为x:的函数F=F(x)该函数是通过命令F(t)=int(L(s)*exp(s*t),s,c-i*inf,c+i*inf)实现的其中c是一个实数,L(s)的奇异点都在直线s=c的左侧,i=sqrt(-1)F =ILAPLACE(L,y)使y取代t:ILAPLACE(L,y)等价于F(y)=int(L(y)*exp(s*y),s,c-i*inf,c+i*inf)F=ILAPLACE(L,y,x)使x的函数取代tILAPLACE(L,y,x)等价于 F(y)= int(L(y)*exp(x*y),y,c-i*inf,c+i*inf)Examples:2
2 L = LAPLACE(F,t) 使自变量用 t 替换 LAPLACE(F,t) 等价于 L(t) = int(F(x)*exp(-t*x),0,inf). L = LAPLACE(F,w,z) 在变换中使 z 取代 s LAPLACE(F,w,z) 等价于 L(z) = int(F(w)*exp(-z*w),0,inf). Examples syms a s t w x laplace(t^5) returns 120/s^6 laplace(exp(a*s)) returns 1/(t-a) laplace(sin(w*x),t) returns w/(t^2+w^2) laplace(cos(x*w),w,t) returns t/(t^2+x^2) laplace(x^sym(3/2),t) returns 3/4*pi^(1/2)/t^(5/2) laplace(diff(sym('F(t)'))) returns laplace(F(t),t,s)*s-F(0) 2、ILAPLACE 是 laplace 逆变换命令. F = ILAPLACE(L) 将自变量为 s 的函数 L 转换成原像得到一个自变量为 t 的函数. 如果 L = L(t), 那么 ILAPLACE 返回一个自变量为 x:的函数 F = F(x). 该函数是通过命令 F(t) = int(L(s)*exp(s*t),s,c-i*inf,c+i*inf)实现的 其中 c 是一个实数,L(s) 的奇异点都在直线 s = c 的左侧, i = sqrt(-1) F = ILAPLACE(L,y) 使 y 取代 t: ILAPLACE(L,y) 等价于 F(y) = int(L(y)*exp(s*y),s,c-i*inf,c+i*inf). F = ILAPLACE(L,y,x) 使 x 的函数取代 t ILAPLACE(L,y,x)等价于 F(y) = int(L(y)*exp(x*y),y,c-i*inf,c+i*inf), Examples:
symsstwxyilaplace(1/(s-1)exp(t)returnssin(x)ilaplace(1/(t^2+1)returnsilaplace(t^(-sym(5/2),x)4/3/pi^ (1/2)*x(3/2)returnsilaplace(y/(y^2 + w^2),y,x)cos(w*x)returnsF(x)ilaplace(sym(laplace(F(x),x,s)"),s,x)returns例4.1求函数ef,etew,coswt的Laplace变换。解:>>symsts;symsawpositive>> at=exp(a*t);>> bt=exp(-a*t);>> ct=exp(i*w*t);>> dt=cos(w*t);>> et=[at bt ct dt];>>Ms=laplace(et)结果为:Ms =[1/(s-a),1/(s+a),1/(s-j*w), s/(s^2+w^2)例4.2验证Laplace延迟性质。解:延迟性质>> syms t s;t0=sym('t0','positive'); %<1>>> ft=sym('f(t-t0)")*sym(Heaviside(t-t0)");3
3 syms s t w x y ilaplace(1/(s-1)) returns exp(t) ilaplace(1/(t^2+1)) returns sin(x) ilaplace(t^(-sym(5/2)),x) returns 4/3/pi^(1/2)*x^(3/2) ilaplace(y/(y^2 + w^2),y,x) returns cos(w*x) ilaplace(sym('laplace(F(x),x,s)'),s,x) returns F(x) 例 4.1 求函数 , , ,cos at at jwt e e e wt − 的 Laplace 变换。 解:>> syms t s;syms a w positive >> at=exp(a*t); >> bt=exp(-a*t); >> ct=exp(i*w*t); >> dt=cos(w*t); >> et=[at bt ct dt]; >> Ms=laplace(et) 结果为: Ms = [ 1/(s-a), 1/(s+a), 1/(s-i*w), s/(s^2+w^2)] 例 4.2 验证 Laplace 延迟性质。 解:延迟性质 >> syms t s;t0=sym('t0','positive'); %<1> >> ft=sym('f(t-t0)')*sym('Heaviside(t-t0)');
>> FS=laplace(ft,t,s),FS t=ilaplace(FS,s,t)运行结果:FS=exp(-s*tO)*laplace(f(t),t,s)FS_t =f(t-tO)*Heaviside(t-t0)5s-1sF(s) =,G(s) =(s+1)(s-2)"s? +w?例4.3求的Laplace逆变换,【Matlab源程序】>>symss t w>> F=ilaplace(5*s-1)/(s+1)/(s-1)%仿真结果为:F=2*exp(t)+3*exp(-t)>>symsstwg=ilaplace(s/(s^2+w^2)>>(%仿真结果为:g =cos(w*t)例4,4(实际应用问题Matlab源程序)用讨论弦的一端x=0固定,x=L一端受迫作谐振动2sinot,弦的初始位移和初始速度为零,给出弦振动的解图。【解】根据题意得定解问题为[un-d'w =0u(x,t) /=0=0, u(x,t) =l=2sinotu,(x,t) l=p=0[u(x,t) =0s解析解为(-1)1u= 2 sin(ox / a)402niatnxsin(ot)+sinsirLLsin(@L/a)a台()-()La计算机实验如下,最后得到的解析解的瀑布图形分布如图所示。4
4 >> FS=laplace(ft,t,s),FS_t=ilaplace(FS,s,t) 运行结果:FS = exp(-s*t0)*laplace(f(t),t,s) FS_t = f(t-t0)*Heaviside(t-t0) 例 4.3 求 的 Laplace 逆变换. 【Matlab 源程序】 >> syms s t w >> F=ilaplace((5*s-1)/(s+1)/(s-1)) %仿真结果为: F =2*exp(t)+3*exp(-t) >> syms s t w >> g=ilaplace((s/(s^2+w^2))) %仿真结果为: g =cos(w*t) 例 4.4(实际应用问题 Matlab 源程序)用讨论弦的一端 固定, 一端 受迫作谐振动 ,弦的初始位移和初始速度为零,给出弦振动的解图。 【解】 根据题意得定解问题为 解析解为 . 计算机实验如下,最后得到的解析解的瀑布图形分布如图所示。 x = 0 x L = 2sint 2 0 0 0 0 ( , ) | 0, ( , ) | 2sin ( , ) | , ( , ) | 0 tt xx x x L t t t u a u u x t u x t t u x t u x t = = = = − = = = = 1 1 2 2 sin( / ) 4 ( 1) π π 2 sin( ) sin sin sin( / ) π ( ) ( ) n n x a n at n x u t L a aL L L n a L + = − = + − 2 2 5 1 ( ) , ( ) ( 1)( 2) s s F s G s s s s w − = = + − +
cleara=1;I=1;A=2.0;W=6;x=0:0.05:1;t=0:0.001:4.3;[X,T]=meshgrid(x,t);uO=A*sin(w*X./a).*sin(w.*T)/sin(w*//a);u=0;for n=1:100;uu=(-1)^(n+1)*sin(n*pi*X/l).*sin(n*pi*a*T/l)/(w*w/a/a-n*n*pi*pi//l);u=u+uu,endu=uO+2*A*w/a/l.*u;figure(1)axis([0 1 -0.05 0.05])h=plot(x,u(1,:),'linewidth,3);set(h,'erasemode''xor');for j=2:length(t);set(h,ydata',u(j.:);axis([0 1 -0.05 0.05])drawnowend
5 clear a=1;l=1; A=2.0;w=6; x=0:0.05:1; t=0:0.001:4.3; [X,T]=meshgrid(x,t); u0=A*sin(w*X./a).*sin(w.*T)/sin(w*l/a); u=0; for n=1:100; uu=(-1)^(n+1)*sin(n*pi*X/l).*sin(n*pi*a*T/l)/(w*w/a/a-n*n*pi*pi/l/l); u=u+uu; end u=u0+2*A*w/a/l.*u; figure(1) axis([0 1 -0.05 0.05]) h=plot(x,u(1,:),'linewidth',3); set(h,'erasemode','xor'); for j=2:length(t); set(h,'ydata',u(j,:)); axis([0 1 -0.05 0.05]) drawnow end