Presentation is loading. Please wait.

Presentation is loading. Please wait.

Maple’s Evaluation Rules 教授 : 蔡桂宏 博士 學生 : 林佳慧 學號 :95356062 95503 統資軟體課程講義.

Similar presentations


Presentation on theme: "Maple’s Evaluation Rules 教授 : 蔡桂宏 博士 學生 : 林佳慧 學號 :95356062 95503 統資軟體課程講義."— Presentation transcript:

1 Maple’s Evaluation Rules 教授 : 蔡桂宏 博士 學生 : 林佳慧 學號 :95356062 95503 統資軟體課程講義

2 Program Full evaluation Levels of evaluation Delayed evaluation

3 Program (continue) Last name evaluation Evaluating function definitions Evaluating function calls A no evaluation rule

4 Program (continue) Evaluating concatenated names Evaluating indexed names Online help for evaluation rules

5 Full evaluation Introducing the kinds of the data styles by normal programming :  文字 - 字元:『 ’ ’ 』或『 ’’ ’’ 』  數字 - 整數和浮點數: 5 、 5.0  邏輯值( boolean ):『 true 』或『 false 』 What is full evaluation?  一口氣計算完畢

6 Full evaluation(Continue) There are exceptions to this rule:  delayed evaluation  levels evaluation  last name evaluation

7

8

9 1.Compare 『 : 』和『;』 2.Maple 語法的結尾是用『 : 』和 『;』 3. 交換變數

10

11 f := x -> f(x) f(x) 的資料會隨著變數 x 的值改變而 變

12 Solve 語法: solve( 函數,變數)

13 此處只有一個變數 (x) Plot 語法: plot( 函數,變數 1 range ,變數 2 range )

14 Seq 語法: seq( 數學式, i= 下界..上界 )

15 Levels of evaluation Purpose:  How do we use the command? The command in levels of evaluation eval(expression , level )

16

17

18

19

20 Delayed evaluation Purpose :  see the command’s output  Compare 『 Delay 』 of evaluation with 『 Level 』 of evaluation  Compare 『 eval(x) 』 with 『 eval(x,n) 』  What happened to the single quote in left equal sign

21 Delayed evaluation  What happened to the double quote in left equal sign?  Compare 『 % 』 with 『 eval(x,n) 』  Another mean about the command’s output in 『 ‘ ’ 』  Explain the function output in 『 rand( ) 』  Compare some different in 『 plot( ) 』

22 Delayed evaluation What is delayed evaluation? 沒有立即要計算變數時使用

23 Delayed evaluation(continue) The command’s output :  『 ’ 變數 ’ 』 : one delayed evaluation  『 ’’ 變數 ’’ 』 : a doubly delayed evaluation  『 ’’’ 變數 ’’’ 』 : a trebly delayed evaluation

24 expression X unassigned

25 function EX.1 C is a delayed parameter

26 EX.2 We can use delayed evaluation to prevent Maple from making the function call.

27

28 EX.3 Compare them…

29 Delayed evaluation(continue) Compare 『 Delay 』 of evaluation with 『 Level 』 of evaluation  『 Delay 』 - 由原來的表示式看 delay 幾次  『 Level 』 - 『 eval(x,n) 』 : 程式由前面開 始找到 x 後,逐行由上往下顯示

30 eval(x) 是 eval(eval(x,2))

31 Delayed evaluation(continue) Compare 『 eval(x) 』 with 『 eval(x,n) 』  The call eval(x) means: Two delayed evaluations.(the same of the eval(eval(x,2)) ) or evaluate x  The call eval(x,n) means: To evaluate the n level of the name x

32

33 evaluate a

34

35 討論 eval(y,1)

36 Delayed evaluation(continue) What happened to the single quote in left equal sign  The first x has its evaluation dealyed and the second x is evaluated right away

37 Delayed evaluation(continue) What happened to the double quote in left equal sign  The first x has its evaluation dealyed and the second x is one delayed evaluated of x

38

39 Delayed evaluation(continue) the command’s output in 『 % 』、 『 % 』  『 % 』 :last expression  『 % 』 : second last expression i.e 『 %% 』 : third last expression

40

41

42 Delayed evaluation(continue) Compare 『 % 』 with 『 eval(x,n) 』  『 % 』 : 由此指令往前找一行  『 eval(x,n) 』 : 程式由前面開始找到 x 後, 逐行由上往下顯示

43

44 Delayed evaluation(continue) Another mean about the command’s output in 『 ‘ ’ 』 :  It can get automatic simplification  It is a very safe way to define y  It is an often used trick in Maple Explain the command’s output in 『 plot( expression in independent variable x,the range of the x) 』

45 『 ‘ u+u ‘ 』 doesn ’ t evaluate to 2u, it simplifies to 2u.

46 『 u+u 』 is evaluated by u=5. 『 ’u+u’ 』 is a simplistic action.

47

48

49

50 Delayed evaluation(continue) Explain the function output in 『 rand( ) 』 :  It can generate a random interger

51 You can find there do not return a random fracion. We can try it again by the common as following:

52 Another way to generate a random fraction:

53 Delayed evaluation(continue) Compare some different as following:  plot(x^2,x=-5..5); v.s plot(x^2,'x'=-5..5);  plot('x'^2,'x'=-5..5); v.s plot('x'^2, x=-5..5);

54 There have the same output

55

56 Last name evaluation Define:  Maple 在計算函數時, 最後一步計算時的 變數

57 Last name is f

58 Last name is k(w) 此處未使用 last name evaluation

59

60 Evaluating function definitions Purpose:  Learning how Maple evaluates function calls

61 If we define f as an expression in x. Now define g as a Maple function.

62 c is a parameter in the definition of g along with x.

63 Evaluating function definitions (continue) How do we define Maple function?  use 『 -> 』  use 『 unapply 』 command

64

65

66

67 Exercise: Explain each the following three sequences of commands.

68

69

70

71 Evaluating function call If f is the name of a Maple function, then an expression of the form f(any-maple-expression)  f was defined using by 『 -> 』 Here is an example of a function and several function calls

72

73

74 Evaluating function call (continue) Some of the function call:  Case 1 : above this page  Case 2 : unevaluated function call

75 g(2) is an unevaluated function call. Case 1 Case 2

76 Evaluating function call (continue) Compare this:

77 A no evaluation rule Purpose:  There have many examples of how unevaluations are used  Explain the command in 『 assigned( ) 』  What is recursion ?

78

79 assign(x=n); x;

80

81 Why? Because x:=‘x’

82

83 A no evaluation rule(continue) Explain the command in 『 assigned( ) 』 :  The assigned function returns true if n has a value other than its own name, and returns false

84 這裡是因為遞迴 (x:=‘x’) 所引起

85 A no evaluation rule(continue) What is recursion?  x=‘x’  f(0)=1 f(1)=1 f(x+2)=f(x+1)+f(x) EX. f(5)=8 f(x) 1 1 2 3 5 8 x 0 1 2 3 4 5 電腦記憶體 x 的地方放 x 的位置

86

87 Evaluating concatenated names Purpose:  find Maple’s rules for evaluating concatenated names What is a concatenated name?  the concatenated name’s command is 『 || 』

88 evaln(expression)

89

90 使用 w||eval(x,n) 有無括號之差別

91

92 The next exercise shows that Maple does allow the use of parentheses for grouping around the right pair of vertical lines.

93

94

95 Evaluating indexed names Purpose:  To understand what indexed name is it Compare 『 x||1:=0 』 with 『 x[1]:=0 』  『 x||1:=0 』 : Maple evaluates x||1 to the name x1  『 x[1]:=0 』 : x[1] is a name. Maple does not need to evaluate it

96

97

98

99

100

101

102

103

104

105

106 Online help for evaluation rules Purpose:  Finding many ways to call for help

107 Online help for evaluation rules (continue) Ways:  『 ? 』  『 F1 』 (version 9)  『 Help/Search 』


Download ppt "Maple’s Evaluation Rules 教授 : 蔡桂宏 博士 學生 : 林佳慧 學號 :95356062 95503 統資軟體課程講義."

Similar presentations


Ads by Google