1 / 22

《 数学实验 》 4

《 数学实验 》 4. 符号变量与符号表达式 微积分基本运算 级数求和与泰勒展开式 常微分方程符号解.    . 符号变量的定义. syms 符号变量 1 符号变量 2 … 例 1. 将 函数 f= y e – x 和 y = sin (x) 进行复合 , 并指定 t 为新的自变量 . syms x y t; f=y*exp(-x); g=sin(x); compose(f,g,y,x,t) ans=sin(t)*exp(-t). 例 2. 转换数值变量为符号变量

Download Presentation

《 数学实验 》 4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 《 数学实验》4 符号变量与符号表达式 微积分基本运算 级数求和与泰勒展开式 常微分方程符号解    

  2. 符号变量的定义 syms符号变量1 符号变量2 … 例1. 将函数f= ye – x和y =sin(x) 进行复合,并指定t为新的自变量. syms x y t; f=y*exp(-x); g=sin(x); compose(f,g,y,x,t) ans=sin(t)*exp(-t) 例2.转换数值变量为符号变量 A=[1/3,1/4;1/5,1/7] B=sym(A) B = [ 1/3, 1/4] [ 1/5, 1/7] 2/22

  3. 符号表达式的创建 ①f=sym('表达式') 例如: f=sym('a*x^2+b*x+c') ②syms 符号变量1 符号变量2 … f=表达式 例3:求f=1/sin(x)的反函数. f=sym(‘1/sin(x)’); finverse(f) ans= asin(1/x) 例4.符号多项式运算 syms x f=2*x^2+3*x-5;g=x^2+x-7; h1 = f+g,h2 = expand(f*g ) factor(h2) h1=3*x^2+4*x-12 h2 = 2*x^4+5*x^3- 16*x^2-26*x+35 ans =(x-1)*(2*x+5)* (x^2+x-7) 3/22

  4. 符号表达式中变量替换 A1=subs(A, ‘old’, ‘new’)修改表达式 用‘new’置换符号表达式A中的’old’ 得到新的符号表达式A1。 例5. 求符号多项式的值 syms a x f=a*x^2+3*x+4; f1=subs(f,a,2) subs(f1,x,5) f1 = 2*x^2+3*x+4 ans = 69 4/22

  5. 将符号矩阵转化为数值矩阵 调用格式:double(A) numeric(A) 例6. A=sym([1/3,2/5;10/7,2/5]) numeric(A) A = [ 1/3, 2/5] [ 10/7, 2/5] ans = 0.3333 2.5000 1.4286 0.4000 5/22

  6. 复杂表达式的化简 syms x y z a b c f=(x+y)*(a+b^c)^z/(x+a)^2 pretty(f) • 常用化简命令: • 降幂排列:collect(P,x); 2. 展开:expand(P); • 3.重叠: horner(P); 4. 因式分解: factor(P); • 5. 化简: simplify(P) 6/22

  7. 微积分基本运算 • limit(f,x,a) —求f表达式在x->a时的极限 • limit(f,x,a,’right(left)’) —求单侧极限 • diff(f) — 对缺省变量求微分 • diff(f,v) — 对指定变量v求微分,适用对多元 函数求偏导数 • diff(f,v,n) —对指定变量v求n阶微分 7/22

  8. int(f) — 对f表达式的缺省变量求积分 • int(f,v) — 对f表达式的v变量求积分 • int(f,v,a,b) — 对f表达式的v变量在(a,b)区间求 定积分 • quad(f,v,a,b) — 对f表达式的v变量在(a,b)区间 求数值积分 例7.求极限 syms x; limit((x-2)/(x^2-4),2) ans=1/4 8/22

  9. 例8. 验证对k=1,2,3,4成立 [diff(sin(x),1),sin(x+pi/2)] ans =[ cos(x), cos(x)] [diff(sin(x),2),sin(x+pi)] ans =[ -sin(x), -sin(x)] [diff(sin(x),3),sin(x+3*pi/2)] ans = [ -cos(x), -cos(x)] [diff(sin(x),4),sin(x+2*pi)] ans =[ sin(x), sin(x)] 9/22

  10. 例9.计算f = 1/(5+4cos(x)) 关于x的导数 syms x f=1/(5+4*cos(x)) ezplot(f) f1=diff(f,x,1) ezplot(f1) int(f1) ans = 1/(5+4*cos(x)) 10/22

  11. 例10. 计算不定积分 syms x int('exp(a*x)*sin(b*x)') g=simplify(ans) g = exp(a*x)*(-b*cos(b*x)+a*sin(b*x))/(a^2+b^2) diff(g) f=simplify(ans) f = exp(a*x)*sin(b*x) 11/22

  12. 例11.绘函数(a = 1, b = 3 )在 [0,3.2]上的图形. 并计算 syms a b x f=exp(a*x)*sin(b*x) f1=subs(f,a,1),f1=subs(f1,b,3) ezplot(f1,0,3.22) F1=simplify(int(f1,1,2)) double( F1 ) ans = -3.1806 12/22

  13. 计算定积分: 例12. f=inline('exp(x).*sin(3*x)') quad(f,1,2) ans = -3.1806 13/22

  14. 例13.求函数 的渐近线、 极值、拐点,并作图. syms x n=3*x^2+6*x-1; d=x^2+x-3; f=n/d; limit(f,inf) ans=3 roots=solve(d) roots=[-1/2+1/2*13^(1/2)] [-1/2-1/2*13^(1/2)] 14/22

  15. ezplot(f) hold on plot([-2*pi 2*pi],[3 3],’g’) plot(double(roots(1))*[1 1],[-5 10],’r’) plot(double(roots(2))*[1 1],[-5 10],’r’) title(‘水平渐近线和垂直渐近线’) hold off 15/22

  16. f1=diff(f); c=solve(f1) ans= [-8/3-1/3*13^(1/2)] [-8/3+1/3*13^(1/2)] ezplot(f) hold on plot(double(c),double(subs(f,c)),’ro’) title(‘函数的极大值和极小值’) text(-5.5,3.2,’局部极小值’) text(-2.5,2,’局部极大值’) hold off 16/22

  17. f2=diff(f1); q=solve(f2); double(q) ans=-5.2635 -1.3682-0.8511i -1.3682+0.8511i q=q(1); ezplot(f,[-9 6]) hold on plot(double(q),double(subs(f,q)),’ro’) title(‘函数的拐点’) text(-7,2,’拐点’) hold off 17/22

  18. 级数求和运算 S=symsum(f,n,a,b) 例14.计算级数 syms k n S=symsum(k,k,1,n);S1=simple(S) S1 =1/2*n*(n+1) S=symsum(k^2,k,1,n);S2=simple(S) S2 =1/6*n*(n+1)*(2*n+1) 18/22

  19. 泰勒级数展开 taylor(f,n,x) —将函数f在原点展开为自变量x的 n-1次麦克劳林多项式. taylor(f,n,x,a) —将函数f在a点展开为自变量x 的n-1次泰勒多项式.其结果为: 19/22

  20. 例15.将函数 展开为7次麦克劳林多 项式. syms x f=1/(5+4*cos(x)) T=taylor(f,8) ans= 1/9+2/81*x^2+5/1458*x^4+49/131220*x^6 20/22

  21. 微分方程符号解 命令格式:dsolve(‘eq1’,···,’con1’,···,’x’) y的一阶导数—— Dy, y的二阶导数—— D2y y = dsolve('Dy=1/(1+x^2)-2*y^2','y(0) = 0','x') y = 2*x/(2*x^2+2) 符号解: y(x)= x / (1 + x 2) 21/22

  22. 例16 P’ =0.02P ( 1 – P/500) 初始条件: P(0)=76 syms P t P=dsolve('DP=0.02*P*(1-P/500)','P(0)=76') P = 500/(1+106/19*exp(-1/50*t)) ezplot(P,0,200),pretty(P) 500 --------------------- 106 1 + --- exp(- 1/50 t) 19 22/22

More Related