1 / 73

数学软件

A comprehensive computer system for advanced mathematics. Maple 软件使用教程课件. 数学软件 提高篇. 数学软件. 提高篇. 数学软件 Maple 篇 第二章 Maple 数学. Maple Maple Maple Maple Maple. 第二章 Maple 数学. 内容提要. 1 . 寻求帮助 2 .Maple 程序设计 3 .Maple 的数据类型 4 . 初等数学实验 5 . 函数 6 .Maple 作图 7 . 微积分实验 8. 输入输出与文件操作 9. 应用专题.

maude
Download Presentation

数学软件

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. A comprehensive computer system for advanced mathematics Maple软件使用教程课件 数学软件 提高篇 数学软件 提高篇

  2. 数学软件Maple篇第二章 Maple数学 Maple Maple Maple Maple Maple

  3. 第二章 Maple数学 内容提要 1.寻求帮助 2.Maple程序设计 3.Maple的数据类型 4.初等数学实验 5.函数 6.Maple作图 7.微积分实验 8.输入输出与文件操作 9.应用专题

  4. 1. 寻求帮助 • 从Help(帮助)菜单按类查找 • ?命令, 例: • ?animate • ?anim • 完整帮助信息,包括六个方面: Function:函数 Calling sequence:命令格式 Parameters:参数 Synopsis:说明 Examples:例 See also:相关条目 • 查找部分信息 info(命令);函数作用 usage(命令); 调用格式 example(命令);实例 related(命令);相关条目 • F1

  5. 选择左侧导航栏打开相应面板进行输入

  6. 2. Maple程序设计 2.1 语句和表达式 • 语句类型

  7. 2. Maple语言基础 2.1 语句和表达式 • 条件语句 格式1: if <condition> then <statement sequence> fi; 格式2: if <condition> then <statement sequence> else <statement sequence> fi; 格式3: if <condition> then <statement sequence> elif <condition> then <statement sequence> else <statement sequence> end if;

  8. 例: restart: f:=proc(x) local y; if x<=0 then y:=0; else if x<=10 then y:=10+2*x; else if x<=20 then y:=30; else y:=30-(x-20)/2; fi; fi; fi; end proc; plot('f(x)',x=-10..50); 或者写成: restart: f:=proc(x) local y; if x<=0 then y:=0; elif x<=10 then y:=10+2*x; elif x<=20 then y:=30; else y:=30-(x-20)/2; end if; end proc; plot('f(x)',x=-10..50);

  9. 循环语句 • for 循环 格式: for <varname> from <start> by <step> to <last> do <statement sequence> end do; for <varname> in <set, matrix, or expression sequence> do <statement sequence> end do; while 循环 格式: while <condition> do <statement sequence> end do;

  10. 例: • x:=0: for i from 1 to 100 do x:=x+i od: x; #for-do-od • 1+2+……+100 • x:=0: for i from 1 to 100 do if x>100 then exit else x:=x+i fi od: x; • 1+2+…+(k-1)<=100, 1+2+…+k>100 #嵌套, 退出 • x:=0 : j:=0: while j<=100 do x:=x+j:j:=j+1 od:x; #while-do-od • 1+2+……+100 • x:=0 : j:=0: for j in {1,4,5,108} while j<=100 do x:=x+j: j:=j+1 od: x; • tot:=0: for z in [1,x,y,q^2,3] do tot:=tot+z end do: tot; • tot=1: for z in 1,x,y,q^2,3 do tot:=tot z end do:tot • s:="The quick brown fox jumped over the lazy dog."; for c from "a" to "z" while 0<searchtext(c,s) do end do; c

  11. 例: • 判断 2^(2i-1)-1, i= 1,2,…,8 是否是素数 • i f – then – else –fi • 命令 isprime(…) • for i to 8 do #省略 from 1 by 1 • a:=2^(2*i-1)-1; • if isprime(a) then print(a, "is a prime") else print(a, "is nota prime") fi • od • 注: 强行换行 Shift+Enter

  12. 例: • 输出2000-2999之间所有的闰年. year:=2000: while year<=2999 do if(year mod 4=0)and(year mod 100<>0)then print(year); elif (year mod 400=0)then print(year); end if; year:=year+1; end do:

  13. break和next • Break Description When the break statement is executed, the result is to exit from the innermost repetition (for/while/do) statement within which it occurs. After exit, execution proceeds, with the first statement following the repetition statement. It is an error if a break is executed in a context other than within a repetition statement. • Examples >L:=[1,2,"abc","a",7.0,infinity]: >for x in L do if type(x,'string') then print(x); break end if end do

  14. break和next • Next Description When the next statement is executed, the result is to exit from the current statement sequence (that is, the do-end do block) that corresponds to the innermost repetition (for/while/do) statement within which it occurs. To exit from the current statement sequence means to allow execution to proceed with the next iteration of this repetition statement. Note: To "proceed with the next iteration'' implies to increment the index of iteration, and then to apply the tests for termination (specified by the to-clause and the while-clause, if present) before proceeding. Thus, an exit from the loop may occur. It is an error if the next statement is executed in a context other than within a repetition statement. • Examples >for n to 3 do if n = 2 then next end if; print(n) end do

  15. 2.2 过程(procedure) • Maple 程序的主要结构 • 关键字: proc local global end • 参数: 可以是空的,如:proc() 可限制参数类型;如:proc(x::numeric, y::numeric) #参数类型有 x::numeric; x::integer; x::symbol; x::string; 可以用args代表所有实际输入的参数,并可用nargs测量参数的长度。

  16. 例如: restart; f:=proc(a,b) a*b; end proc; f(2,3); f('the', 'student'); restart; f:=proc(a,b) a+b; a-b; a*b; a/b; end proc: f(10,5);

  17. 局部变量和全局变量 • a: =1; • f: =proc( ) local a; a: =105615750/456210 evalf(a/2); end: • f( ); • a; • a: =1; • f: =proc( ) global a; a: =105615750/456210 evalf(a/2); end: • f( ); • a;

  18. 例: • 过程 • 内部变量 • 判断参数长度 • 赋值 • 循环 • 判断大小 • 输出 • 试用 • Max:=proc() • local i,m; • if nargs=0 then return(Fail) end if; • m:=args[1]; • for i from 2 to nargs do • if args[i]>m then m:=args[i] end if ; • end do; • m; • end: • Max(2,5,4,7,4,6,4);

  19. 2.3 递归调用 函数或过程调用自身,称为递归。 例如, 计算自然数的阶乘: fact:=proc(n::nonnegint); if n<2 then n; else fact(n-1)*n; fi; end proc: fact(5);

  20. 2.4 返回与嵌套 • 返回 函数或过程中,可以使用return将结果返回。例如: f:=proc(x) local d,m; if x<=250 then d:=0;m:=x*(1-d);return(m); elif x<=500 then d:=0.05;m:=x*(1-d);return(m); else d:=0.075;m:=x*(1-d);return(m); fi; end proc: f(501);

  21. 2.4 返回与嵌套 • 嵌套 一个函数或过程中,调用另一个函数或过程,称为嵌套。例如: fact:=proc(n::nonnegint); if n<2 then n; else fact(n-1)*n; fi; end proc: g:=proc(n) local sum,i,g;sum:=0; for i from 1 to n do sum:=sum+fact(i); end do; return(sum); end proc;

  22. 2.5 封装程序 下面通过具体实例制作Maple软件包。 制作一个包含能自动绘制正弦、余弦、正切曲线的软件包。 xu[sin1]:=proc() plot(sin(x),x=-2*Pi..2*Pi) end proc; xu[cos1]:=proc() plot(cos(x),x=-2*Pi..2*Pi) end proc; xu[tg]:=proc() plot(tan(x),x=-2*Pi..2*Pi,y=-5..5) end proc; xu[sst]:=proc() plot({sin(x),cos(x),tan(x)},x=-2*Pi..2*Pi,y=-5..5) end proc; save(xu,“xu.m”); #将文件xu.m储存到Maple的安装目录 save(xu,“d:\\mfile\\xu.m”); #储存到“已存在的指定目录” with(xu); #调用软件包xu

  23. 2.5 封装程序 如果退出Maple后,要调用已保存的软件包,需要先读取保存的文件: read(“xu.m”); #读取软件包xu with(xu); #调用软件包xu sst(); #执行xu中的sst条款

  24. 3. Maple的数据类型 3.1 基本数据类型

  25. 3.2 复合数据类型

  26. 3.3 软件包 • 软件包:

  27. 4. 初等数学实验 4.1 数字运算 • 整数、分数运算 >p:=1153*(3^58+5^40)/(29!-7^36); • 常用运算符:+,-,*,/,^或**,abs( ) • 浮点运算 >evalf(p,20); 2→ 2.0 • 数学常数 Pi(p大写)、I(复数单位)、infinity(无穷) >Pi; infinity;

  28. 4.2 基本代数运算 • 运算符 基本初等函数 sqrt、^ 、exp、log、sin、cos、tan、cot、sec、csc、arc 数值显示

  29. 例: • 3!**6; • sin(5); exp(1); • %;%% • evalf(Pi,100);

  30. 4.3 多项式 • 定义 • y:=x-> x^3-2*x^2-5*x+6;………….y(x) • z:=x^2-5*x+4; • 算术运算 • 例 • 将100!分解成素数?第1000个素数是什么? • ifactor(100!);ithprime(1000); • 例 • w:=y(x)/z; y(x)*z; y(x)-z; • gcd(y(x),z); lcm(y(x),z); • quo(y(x),z,x,'r');r;

  31. 重组 • 例: • factor(y(x)); (2*x^2-5*x+6)*z; expand(%); • 求根 • 例: • t:=x^3+2; fsolve(t);fsolve(t,x,complex); • realroot(t); roots(t); solve(t); evalf(%);

  32. 4.4 有理式 • 例: s:= (x^3-2*x^2-5*x+6)/(x^2-5*x+4); • 例: • %+x; • simplify(%);simplify(%%%); Maple

  33. 5. 函数 • 自定义函数 赋值法 f:=数 或 表达式; (后赋值将替换以前的赋值, 加单引号表示符号变量) 箭头算子法 f:=x->表达式、f:=(x,y)-> 表达式; >y:=x^2-5*x+3;y(3); >y:=x->x^2-5*x+3;y(3); • 函数运算 函数可以进行+,-,*,/,@(复合运算)

  34. 说明: 函数定义

  35. 例: • lc := proc( s, u, t, v ) • description "form a linear combination of the arguments": • s * u + t * v • end proc: • print( lc ); • lc( Pi, x, -I, y ); • p:=proc(x) if x>1 then x^2-1 else 2*(1-x) fi end:p(2); • p:=piecewise(x>1,x^2-1,2*(1-x) );

  36. 6. Maple作图 • 基本命令 • 二维图形

  37. 三维图形 • 其他

  38. 例: • > plot(x^2,x=-3..3); >plot(2*x^3-6*x,x=-2.5..2.5,style=point,symbol=box); >plot([4*x-x^2+2,x^2,3*x+1],x=-2..5, color=[red,blue,green], linestyle= [20, 20]) >f:=10*sin(x)*exp(-x^2):#先定义函数 >plot(f,x=-2..5,color=green,linestyle=20);作上述函数图 >f:=x->sin(x)*exp(x): plot(f(x),x=-2..5); • > plot({[sin(t),cos(t),t=0..2*Pi],2*x-1},x=-2..2,y=-2..2); • >with(plots):animate(sin(t*x),x=-2*Pi..2*Pi, t=.5..4, color=1, linestyle =30);

  39. • 极坐标 > plot([sin(4*x),x,x=0..2*Pi],coords=polar,thickness=3); >with(plots):animate([sin(x*t),x,x=-4..4],t=1..4, coords=polar, numpoints=100,frames=100); • 曲面图: > plot3d(x^2+y^2,x=-2..2,y=-2..2,color=0.1); • 动画图 > with(plots): > animate3d( cos(t*x)*sin(t*y), x=-Pi..Pi, y=-Pi..Pi, t=1..2 ); • 三维曲线图:plot3d([x(t),y(t),z(t)],t=t1..t2],z=z1..z2,选项); >plot3d([cos(t),sin(t),t],t=0..3*Pi,z=a..b);

  40. 7. 微积分实验 7.1 极限 格式 limit(f(x), 极限点,选项)为极限计算指令 Limit (f(x), ……) 为极限符号,可用value显示值

  41. 例: • >Limit((x-sin(x))/x^3,x=0)=limit((x-sin(x))/x^3,x=0); >Limit(exp(1/x),x=0,left)=limit(exp(1/x),x=0,left); >Limit((x^2-3*x+2)/(5*x^2-4),x=infinity)=limit((x^2-3*x+ 2) /(5*x^2-4),x=infinity); > Limit(x^sin(x),x=0)=limit(x^sin(x),x=0); > Limit(sin(x),x=infinity)=limit(sin(x),x=infinity); > Limit(exp(x),x=-infinity)=limit(exp(x),x=-infinity); • 注:函数若由箭头算子定义,求极限函数要用f(x)形式 >y:=x->exp(x):limit(y,x=3);limit(y(x),x=3);

  42. 7.2 导数 • 格式 diff(f,x1,x2,…) x1,x2,…为各次求混合导数的自变量 diff(f,x$m,y$n) m,n分别为对自变量x、y求导阶数 Diff 为求导符号,可用value显示值

  43. 例: • > Diff(exp(x^2),x)=diff(exp(x^2),x); >Diff(log(x+sqrt(1+x^2)),x$2); value(Diff(log(x+sqrt(1+x^2)),x$2)); simplify(value(Diff(log(x+sqrt(1+x^2)),x$2))); >Diff(x^2*cos(y),x,y$3)=diff(x^2*cos(y),x,y$3); >subs(x=3,y=4,diff(exp(sqrt(x^2+y^2)+x),x,y)); evalf(subs(x=3,y=4,diff(exp(sqrt(x^2+y^2)+x),x,y))); #计算函数在(3,4)点混合导数值 • 注:函数若由箭头算子定义,求导函数要用f(x)形式 >y:=x->sin(1/x):diff(y,x);diff(y(x),x);

  44. 7.3 积分 • 格式 不定积分 int(f,x) 定积分 int(f,x=a..b) Int为积分符号,用value显示值 重积分 int(int(f(x,y),y=y1(x)..y2(x)),x=a..b)

  45. 例: • > Int(2*x*sin(x),x)=int(2*x*sin(x),x)+c; > Int(sqrt(a^2+x^2),x)=int(sqrt(a^2+x^2),x)+C; >Int((x-2)/(x^3-1),x)=int((x-2)/(x^3-1),x)+C; > value( Int(x*ln(x),x)); >Int((x-2)/(x^3-1),x=2..3)=int((x-2)/(x^3-1),x=2..3); >int(sin(sin(x)),x=0..2);Evalf(%); • 注:箭头算子定义函数要用int(f(x),x) >f:=x->x^2-1/x:int(f(x),x); • >Int(Int(abs(y)*x^2,y=-sqrt(1-x^2)..sqrt(1-x^2)),x=-1..1) =int(int(abs(y)*x^2,y=-sqrt(1-x^2)..sqrt(1-x^2)),x=-1..1) ;

  46. 7.4 循序渐进 • 例: • f:=sqrt(x+1)/sin(x); iscont(f,x=-0.5..1); discont(f,x); • 例: • f:=sqrt(x+1)/sin(x); diff(f,x); D(f); D(f)(2); • g:=x->sqrt(x+1)/sin(x); diff(g,x); D(f); D(f)(2); evalf(%); • eqn:=x^2+y^2=1; implicitdiff(eqn,y,x);

  47. • with(student): • expr:=Int(x^2*exp(x),x); • intparts(expr,x^2); #设u=x^2, 分部积分 • value(%);

  48. 7.5 级数 • 级数 • 例: • Sum(x^n/n!,n=0..infinity)=sum(x^n/n!,n=0..infinity); • Sum(1/k^2,k=1..infinity):%=value(%); • 1/(1-x)=series(1/(1-x),x); taylor(1/(1-x),x); • sin(x)=series(sin(x),x=Pi/2,8); > • exp(x)/x=taylor(exp(x)/x,x); • series(exp(x)/x,x); • x^3/(x^4+4*x-5)=series(x^3/(x^4+4*x-5),x=infinity);

  49. • 幂级数 • with(powseries): • powcreate(f(n)=2^n/n!): • powcreate(h(n)=(-1)^(n+1)/n,h(0)=1): • Sum(2^n*x^n/n!,n=0..infinity)=tpsform(f,x,7); • powcreate(h(n)=(-1)^(n+1)/n,h(0)=1): • Sum((-1)^(n+1)*x^n/n,n=1..infinity)=tpsform(h,x,5); • powcreate(v(n)=(v(n-1)+v(n-2))/4,v(0)=4,v(1)=2): • tpsform(v, x); 一.> >

  50. 7.6 方程求解 • solve(方程,未知数);fsolve(方程,未知数,选项);解数值解 选项:1.complex复数域上求根 2.fulldigits保持精度 3.maxsols=n求n个解 4.范围(省略“=”号为=0) >p:=x->x^2+2*x-3:plot(p(x),x=-4..2); solve(p(x)); >fsolve(p(x)=12,x); >t:=solve(6*x^4-35*x^3+22*x^2+17*x-10):t1:=eval(t[1]); >t2:=eval(t[2]); t3:= eval(t[3]); t4:=eval (t [4]); >p:=x->12*x^5+32*x^4-57*x^3-213*x^2-104*x+60: >plot(p,-5..5,650.. -300); solve(p(x));

More Related