Y >_< I Y 一,一一,一 I Maple's Control Statements 教授:蔡桂宏 博士 學生:張杰楷 95503 統資軟體課程講義95503 統資軟體課程講義.

Slides:



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

Divide-and-Conquer. 什麼是 divide-and-conquer ? Divide 就是把問題分割 Conquer 則是把答案結合起來.
Chapter 10 馬可夫鏈 緒言 如果讀者仔細觀察日常生活中所發生的 諸多事件,必然會發現有些事件的未來 發展或演變與該事件現階段的狀況全然 無關,這種事件稱為獨立試行過程 (process of independent trials) ;而另一些 事件則會受到該事件現階段的狀況影響。
: Arrange the Numbers ★★★☆☆ 題組: Contest Archive with Online Judge 題號: 11481: Arrange the Numbers 解題者:李重儀 解題日期: 2008 年 9 月 13 日 題意: 將數列 {1,2,3, …,N}
布林代數的應用--- 全及項(最小項)和全或項(最大項)展開式
第七章 抽樣與抽樣分配 蒐集統計資料最常見的方式是抽查。這 牽涉到兩個問題: 抽出的樣本是否具有代表性?是否能反應出母體的特徵?
: A-Sequence 星級 : ★★☆☆☆ 題組: Online-judge.uva.es PROBLEM SET Volume CIX 題號: Problem D : A-Sequence 解題者:薛祖淵 解題日期: 2006 年 2 月 21 日 題意:一開始先輸入一個.
Reference, primitive, call by XXX 必也正名乎 誌謝 : 部份文字取於前輩 TAHO 的文章.
What is static?. Static? 靜態 ? class Test { static int staticX; int instanceX; public Test(int var1, int var2) { this.staticX = var1; this.instanceX =
指導教授:陳淑媛 學生:李宗叡 李卿輔.  利用下列三種方法 (Edge Detection 、 Local Binary Pattern 、 Structured Local Edge Pattern) 來判斷是否為場景變換,以方便使用者來 找出所要的片段。
1.1 線性方程式系統簡介 1.2 高斯消去法與高斯-喬登消去法 1.3 線性方程式系統的應用(-Skip-)
: Boxes ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11003: Boxes 解題者:蔡欣燁 解題日期: 2007 年 3 月 19 日.
亂數產生器安全性評估 之統計測試 SEC HW7 姓名:翁玉芬 學號:
Lecture 8 Median and Order Statistics. Median and Order Statistics2 Order Statistics 問題敘述 在 n 個元素中,找出其中第 i 小的元素。 i = 1 ,即為找最小值。 i = n ,即為找最大值。 i = 或 ,即為找中位數。
Review of Chapter 3 - 已學過的 rules( 回顧 )- 朝陽科技大學 資訊管理系 李麗華 教授.
JAVA 程式設計與資料結構 第二章 JAVA 程式基本概念及操作. 第一個程式 /* * 這是第一個程式 (FirstP.java) */ class FirstP{ public static void main(String args[]){ System.out.println("Whatever.
STAT0_sampling Random Sampling  母體: Finite population & Infinity population  由一大小為 N 的有限母體中抽出一樣本數為 n 的樣 本,若每一樣本被抽出的機率是一樣的,這樣本稱 為隨機樣本 (random sample)
1. 假設以下的敘述為一未提供 “ 捷徑計算 ” 能力的程式段,試用程 式設計的技巧,使此敘述經此改 寫的動作後,具有與 “ 捷徑計算 ” 之 處理方法相同之處理模式。 if and then E1 else E2 endif.
JAVA 程式設計與資料結構 第十四章 Linked List. Introduction Linked List 的結構就是將物件排成一列, 有點像是 Array ,但是我們卻無法直接經 由 index 得到其中的物件 在 Linked List 中,每一個點我們稱之為 node ,第一個 node.
Monte Carlo Simulation Part.2 Metropolis Algorithm Dept. Phys. Tunghai Univ. Numerical Methods C. T. Shih.
第一章 演算法:效率、分析與量級 1.1演算法 1.2發展有效率演算法的重要性 1.3演算法的分析 1.4量級(Order)
2009fallStat_samplec.i.1 Chap10 Sampling distribution (review) 樣本必須是隨機樣本 (random sample) ,才能代表母體 Sample mean 是一隨機變數,隨著每一次抽出來的 樣本值不同,它的值也不同,但會有規律性 為了要知道估計的精確性,必需要知道樣本平均數.
組員 : 林士恆 許嘉宏 不可計算函數 不可計算函數 根據 12.2 的 Church-Turing 命題,當我們找到一個杜林不 可計算的函數時,一般就相信它是個不可計算的函數。 簡單來說,就是一個計算超出今日電腦能力的函數。
Introduction to Java Programming Lecture 17 Abstract Classes & Interfaces.
:Problem D: Bit-wise Sequence ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10232: Problem D: Bit-wise Sequence 解題者:李濟宇 解題日期: 2006 年 4 月 16.
: The largest Clique ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11324: The largest Clique 解題者:李重儀 解題日期: 2008 年 11 月 24 日 題意: 簡單來說,給你一個 directed.
: War on Weather ★★☆☆☆ 題組: Contest Volumes Archive with Online Judge 題號: 10915: War on Weather 解題者:陳明凱 題意:題目總共會給你 k 個點座標代表殺手衛星的位置, 距離地球表面最少 50 公里以上,並且會給你.
: Happy Number ★ ? 題組: Problem Set Archive with Online Judge 題號: 10591: Happy Number 解題者:陳瀅文 解題日期: 2006 年 6 月 6 日 題意:判斷一個正整數 N 是否為 Happy Number.
: Fast and Easy Data Compressor ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10043: Fast and Easy Data Compressor 解題者:葉貫中 解題日期: 2007 年 3.
Chapter 2 Getting Started Insertion Sort: 能有效率地排序小數字的演算法 範例 :
: Count DePrimes ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11408: Count DePrimes 解題者:李育賢 解題日期: 2008 年 9 月 2 日 題意: 題目會給你二個數字 a,b( 2 ≦ a ≦ 5,000,000,a.
: Multisets and Sequences ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11023: Multisets and Sequences 解題者:葉貫中 解題日期: 2007 年 4 月 24 日 題意:在這個題目中,我們要定義.
:Nuts for nuts..Nuts for nuts.. ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 10944:Nuts for nuts.. 解題者:楊家豪 解題日期: 2006 年 2 月 題意: 給定兩個正整數 x,y.
資料結構實習-一 參數傳遞.
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2008.
公用品.  該物品的數量不會因一人的消費而受到 影響,它可以同時地被多人享用。 角色分配  兩位同學當我的助手,負責:  其餘各人是投資者,每人擁有 $100 , 可以投資在兩種資產上。  記錄  計算  協助同學討論.
: Problem G e-Coins ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10306: Problem G e-Coins 解題者:陳瀅文 解題日期: 2006 年 5 月 2 日 題意:給定一個正整數 S (0
: Beautiful Numbers ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11472: Beautiful Numbers 解題者:邱經達 解題日期: 2011 年 5 月 5 日 題意: 若一個 N 進位的數用到該.
函式 Function Part.2 東海大學物理系‧資訊教育 施奇廷. 遞迴( Recursion ) 函式可以「呼叫自己」,這種動作稱為 「遞迴」 此程式的執行結果相當於陷入無窮迴圈, 無法停止(只能按 Ctrl-C ) 這給我們一個暗示:函式的遞迴呼叫可以 達到部分迴圈的效果.
JAVA 程式設計與資料結構 第二十章 Searching. Sequential Searching Sequential Searching 是最簡單的一種搜尋法,此演 算法可應用在 Array 或是 Linked List 此等資料結構。 Sequential Searching 的 worst-case.
資料結構實習-二.
演算法 8-1 最大數及最小數找法 8-2 排序 8-3 二元搜尋法.
: Expect the Expected ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11427: Expect the Expected 解題者:李重儀 解題日期: 2008 年 9 月 21 日 題意:玩一種遊戲 (a game.
845: Gas Station Numbers ★★★ 題組: Problem Set Archive with Online Judge 題號: 845: Gas Station Numbers. 解題者:張維珊 解題日期: 2006 年 2 月 題意: 將輸入的數字,經過重新排列組合或旋轉數字,得到比原先的數字大,
Chapter 2. Recurrence Relations (遞迴關係)
Chapter 10 m-way 搜尋樹與B-Tree
演算法課程 (Algorithms) 國立聯合大學 資訊管理學系 陳士杰老師 Course 7 貪婪法則 Greedy Approach.
JAVA 程式設計與資料結構 第十六章 Hash Tables. Introduction Hash Tables 結構為一個 Array ,稱之為 Bucket array 。 如果想要新增一個物件,要根據這個物件的特性 將其加入 Hash Table 內。 Bucket Array 用 A 來代替,其.
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2009.
計算機概論 第6章 數位邏輯設計.
2005/7 Linear system-1 The Linear Equation System and Eliminations.
5 重複迴圈 5.1 增減運算符號 增量運算符號 減量運算符號
INTRODUCTION TO MATLAB SHAWNNTOU. What Is MATLAB? MATLAB® is a high-performance language for technical computing. MATLAB® is a high-performance language.
: Problem E Antimatter Ray Clearcutting ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11008: Problem E Antimatter Ray Clearcutting 解題者:林王智瑞.
第 6 章 迴圈結構 6-1 計數迴圈 6-1 計數迴圈 6-2 條件迴圈 6-2 條件迴圈 6-3 巢狀迴圈 6-3 巢狀迴圈 6-4 While/End While 迴圈 6-4 While/End While 迴圈 6-5 跳出迴圈 6-5 跳出迴圈 6-6 VB.NET 的錯誤處理 6-6 VB.NET.
Teacher : Ing-Jer Huang TA : Chien-Hung Chen 2015/6/30 Course Embedded Systems : Principles and Implementations Weekly Preview Question CH7.1~CH /12/26.
: Wine trading in Gergovia ★★☆☆☆ 題組: Contest Volumes with Online Judge 題號: 11054: Wine trading in Gergovia 解題者:劉洙愷 解題日期: 2008 年 2 月 29 日 題意:在 Gergovia.
:Commandos ★★★☆☆ 題組: Contest Archive with Online Judge 題號: 11463: Commandos 解題者:李重儀 解題日期: 2008 年 8 月 11 日 題意: 題目會給你一個敵營區內總共的建築物數,以及建築物 之間可以互通的路有哪些,並給你起點的建築物和終點.
函式 Function 東海大學物理系‧資訊教育 施奇廷. 函式簡介 當程式越來越大、越複雜時,程式的維護、 除錯會變得更困難,此時必須引入函式來 簡化程式或將程式分段,將程式重複的部 分改寫為函式,將程式「模組化」 這種作法有下列優點:節省程式發展的時 間、邏輯容易瞭解、程式容易除錯、可分 工合作完成程式.
11 Ch05 遞迴 淡江大學 周清江 1. 2  遞迴函數乃是一個自己反覆呼叫自己的函數  一個典型的遞迴演算法 n! = n * (n-1)! = n * (n-1) * (n-2)! = n * (n-1) * (n-2) * (n-3)! = … = n * (n-1) * (n-2)
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2010.
: SAM I AM ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11419: SAM I AM 解題者:李重儀 解題日期: 2008 年 9 月 11 日 題意: 簡單的說,就是一個長方形的廟裡面有敵人,然 後可以橫的方向開砲或縱向開砲,每次開砲可以.
: Finding Paths in Grid ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11486: Finding Paths in Grid 解題者:李重儀 解題日期: 2008 年 10 月 14 日 題意:給一個 7 個 column.
:Problem E.Stone Game ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10165: Problem E.Stone Game 解題者:李濟宇 解題日期: 2006 年 3 月 26 日 題意: Jack 與 Jim.
著作權所有 © 旗標出版股份有限公司 第 14 章 製作信封、標籤. 本章提要 製作單一信封 製作單一郵寄標籤.
:Rings and Glue ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10301: Rings and Glue 解題者:施博修 解題日期: 2011 年 5 月 18 日 題意:小約翰有了個大麻煩,他不小心將 rings.
幼兒行為觀察與記錄 第八章 事件取樣法.
: How many 0's? ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11038: How many 0’s? 解題者:楊鵬宇 解題日期: 2007 年 5 月 15 日 題意:寫下題目給的 m 與 n(m
McGraw-Hill/Irwin © 2003 The McGraw-Hill Companies, Inc.,All Rights Reserved. 肆 資料分析與表達.
Presentation transcript:

Y >_< I Y 一,一一,一 I Maple's Control Statements 教授:蔡桂宏 博士 學生:張杰楷 統資軟體課程講義95503 統資軟體課程講義

Y >_< I Y 一,一一,一 I 內容綱要 5.1 Introduction 5.2 Repetition statements 5.3 More loop examples 5.4 Conditional statements 5.5 Boolean expressions 5.6 For-loop like commands 5.7 Statements vs. expressions

Y >_< I Y 一,一一,一 I 內容綱要 5.8 Print levels, printlevel, and print commands 5.9 Procedures that return unevaluated or return NULL 5.10 Online help for control statements

Y >_< I Y 一,一一,一 I 5.1 Introduction 為了寫些有趣的程式,需要學習兩種新的 Maple commands : 1. Repetition statement 2. Conditional statement 合稱為 control statements.

Y >_< I Y 一,一一,一 I 5.2 Repetition statements For-loop 語法: for index_variable from initial_value to final_value by step_size do sequence_of_Maple_commands od 一些例子

Y >_< I Y 一,一一,一 I 5.2 Repetition statements 注意: 1. by step_size 可以省略,當 initial_value 小於 final_value 時,且省略 step_size ,則內定 step_size 值為 1 。 2. 當 index_variable 遞增 by step_size 到達一個大於 final_value 的值時,或 step_size 為負,則當 index_variable 遞減 by step_size 到達一個小於 final_value 的值時,則 for-loop 將會停止。 3. for-loop 不承認 index_variable 在之前所設定的值。 Ex Ex

Y >_< I Y 一,一一,一 I 5.2 Repetition statements 注意: 4. 當 for-loop 停止, index_variable 值都會大 ( 小 ) 於 final_value ,但是確切的大 ( 小 ) 多少是由 initial_value, final_value, 與 step_size 所決定。 Ex Ex 5. from initial_value 與 to final_value 也都可以省略,當 from initial_value 省略時,則內定 initial_value 值為 1 , Ex ;不過當你省略 to final_value ,此 for-loop 將不停Ex 止。

Y >_< I Y 一,一一,一 I 5.2 Repetition statements 產生 “Tables” : for-loop 常被使用產生 “Tables” of results : Ex :某些整數的 10 進位、 2 進位與 16 進位互換Ex :某些整數的 10 進位、 2 進位與 16 進位互換 Ex : Table of polynomials and their factorizationsEx : Table of polynomials and their factorizations 注意: 1. Print 的結尾Print 的結尾 2. Od 的結尾Od 的結尾

Y >_< I Y 一,一一,一 I 5.2 Repetition statements 對 for-loop 的結果命名: 我們可以利用 for-loop 快速的得到運算結果 Ex ,可是當我 們想給每次 for-loop 的結果命名,該如何做?可以利用前 幾章所提過的方法: Ex 1. Concatenated namesConcatenated names 2. Indexed namesIndexed names Ex :找出前十個質數Ex :找出前十個質數

Y >_< I Y 一,一一,一 I 5.2 Repetition statements For-in-loop 語法: for index_variable in data_structure do sequence_of_Maple_commands od 一些例子

Y >_< I Y 一,一一,一 I 5.2 Repetition statements While-loop 語法: while boolean_expression do sequence_of_Maple_commands od 只要 boolean_expression 為真, while-loop 會反覆執行。 Ex :判定 1~10 是否為質數Ex :判定 1~10 是否為質數 注意: 當我們不知迴圈確切要做幾次時,使用 while-loop 較佳。 Ex :找最接近 1000 的兩個質數Ex :找最接近 1000 的兩個質數

Y >_< I Y 一,一一,一 I 5.2 Repetition statements Nest for-loop : 利用 Ex 說明。 Ex :計算多少質數小於 2^i ,且 i 從 2 到 18 。Ex :計算多少質數小於 2^i ,且 i 從 2 到 18 。 A loop that combines : Ex :找出第一個有 1000 位數的階層Ex :找出第一個有 1000 位數的階層 Ex : For-in-while-loopEx : For-in-while-loop

Y >_< I Y 一,一一,一 I 5.3 More loop examples Example 1: Riemann sums Example 2: Pascal‘s triangle Example 3: Periodic extensions Example 4: Drawing graphs Example 5: Butterfly curve Example 6: Animations

Y >_< I Y 一,一一,一 I 5.4 Conditional statements If-then-else-fi 語法: if boolean_expression then sequence_of_Maple_commands else sequence_of_Maple_commands fi 可簡化為: if boolean_expression then sequence_of_Maple_statements fi

Y >_< I Y 一,一一,一 I 5.4 Conditional statements Ex : Ex :一個簡單例子Ex :一個簡單例子 Ex :隨機產生 0 或 1 ,如果是 0 則輸出 heads ,不是則輸出 tails.Ex :隨機產生 0 或 1 ,如果是 0 則輸出 heads ,不是則輸出 tails. If 與 for-in-loop 的結合: Conditional statements 單獨使用其作用相當有限,因此其 常與程序或 loop 結合,為其 body 的一部份。 Ex : What percentage of the random integers were 10'sEx : What percentage of the random integers were 10's

Y >_< I Y 一,一一,一 I 5.4 Conditional statements Conditional statements 與數學: Ex :Ex : Some exercises : Ex Ex Nest conditional statements : Ex :Ex : Ex : Other nested conditional statements and nested proceduresEx : Other nested conditional statements and nested procedures

Y >_< I Y 一,一一,一 I 5.4 Conditional statements If-then-elif-then-else-fi : if boolean_expression then sequence_of_Maple_commands elif boolean expression then sequence_of_Maple_commands else sequence_of_Maple_commands fi

Y >_< I Y 一,一一,一 I 5.5 Boolean expressions Boolean expression 常被使用於 while-loops 與 conditional statements 。 Ex Ex Boolean expressions are made up of the three logical operators (and, or, not), the relational operators (, >=, =, <>), and functions that return true or false (i.e., boolean functions, ex : isprime ). We call and and or binary boolean operators and we call not a unary boolean operator.

Y >_< I Y 一,一一,一 I 5.5 Boolean expressions and, or, not 真值表: 一些例子 XYX and YX or Y false truefalsetrue false true Xnot X falsetrue false

Y >_< I Y 一,一一,一 I 5.5 Boolean expressions The following is not a boolean expression in Maple, though it would be a true statement in a mathematics book. ExEx There is a whole algebra to boolean expressions that specifies the order of precedence for all of the boolean operations, associativity rules for each boolean operation, and algebraic identities for boolean expressions. ExEx

Y >_< I Y 一,一一,一 I 5.6 For-loop like commands The three commands seq, add, and mul act very much like for-loops. In a sense they are abbreviations of special purpose for-loops. Seq : The seq command is used to create expression sequences. ExEx

Y >_< I Y 一,一一,一 I 5.6 For-loop like commands Add : The add command is a direct analogue in Maple to sigma notation. An add command of the form add( f(n), n=a..b ) means exactly the same thing as and their for-loop equivalent is result := 0: for n from a to b do result := result + f(n) od: result; ExEx

Y >_< I Y 一,一一,一 I 5.6 For-loop like commands Mul : The mul command is a direct analogue in Maple to mathematical product notation. A mul command of the form mul( f(n), n=a..b ) means exactly the same thing as and their for-loop equivalent is result := 1: for n from a to b do result := result * f(n) od: result; ExEx

Y >_< I Y 一,一一,一 I 5.6 For-loop like commands Sum and product commands : They are two Maple commands that are related to the add and mul command but they are not abbreviations for for-loops. ExEx 注意: Here is one tricky difference between add, mul on the one hand and sum, product. The index variable in an add or a mul command is local variables. The index variable in the sum and product commands are global variables. ExEx

Y >_< I Y 一,一一,一 I 5.7 Statements vs. expressions In Maple, we cannot use statements where you are supposed to use expressions. The most common kinds of statements in Maple are repetition statements, conditional statements, assignment statements, and the restart statement. Almost everything else in Maple is an expression (and every expression is also a statement). Ex Ex Maple allowed a conditional statement after the arrow but not a repetition statement. ExEx

Y >_< I Y 一,一一,一 I 5.8 Print levels, printlevel, and print commands 當你將 for-loops 放在 if-statements 中,或將 if-statements 放在 for-loops 中,將不會產生你所預期的結果 Ex ,這是因 為 Maple 的 print levels 概念。系統預設為印出 the first print level 的結果,不過上述情況的 print levels 常常不是 1 , 因此可用下列兩種方式解決: Ex 1. Use the print command, which always prints no matter what print level it is at. ExEx 2. Change the value of the printlevel variable. ExEx 雖然此兩種方式產生的結果,看來是相同地,不過事實上 它們是有差異的,請看以下說明。

Y >_< I Y 一,一一,一 I 5.8 Print levels, printlevel, and print commands The print command returns a special result called NULL, which is actually a name for the empty expression sequence. The last result variable, %, has the property that it always ignores the result NULL. This is why the print command did not have any effect on the last result variable. ExEx So putting print commands in a procedure can change what the return value of the procedure is. On the other hand, changing the value of printlevel does not have any effect on the return value of a procedure. So there is a difference between using print commands in a procedure and changing printlevel. ExEx

Y >_< I Y 一,一一,一 I 5.9. Procedures that return unevaluated or return NULL We defined procedures that used if-then-else-fi statements to implement piecewise defined functions. But there were some subtle problems with those procedures that we left unresolved in that section. ExEx Here is another, slightly different example of a function returning unevaluated. ExEx Here is another example of a command that returns NULL. ExEx

Y >_< I Y 一,一一,一 I 5.10 Online help for control statements Repetition statements : ?for Conditional statements : ?if Boolean expressions : ?boolean Seq, Add, and Mul : ?seq, ?add Sum and Product commands : ?sum, ?product Printlevel variable : ?printlevel Print command : print NULL represents : ?NULL “Fail return" : ?RETURN, ?procname All of Maple's statements : ?statement

Y >_< I Y 一,一一,一 I ~The End~