Skip to Main Content
Mathematica 錦囊妙計
book

Mathematica 錦囊妙計

by Sal Mangano
April 2014
Beginner to intermediate content levelBeginner to intermediate
830 pages
15h 21m
Chinese
GoTop Information, Inc.
Content preview from Mathematica 錦囊妙計
744
|
第十九章
解決方案
使用訣竅 2.10 中提到的
Reap
Sow
指令,將資料擷取出來以便於利用模式匹配或繪圖
方式進行分析。舉例來說,假設你有一個稱為
func
的函數,你想知道哪些引數會導致
其輸出值為負,為方便起見,以下設計了一個範例以凸顯這個功能,你也可以自行設計
類似的函數進行測試。
以上可以看出共有 90 組引數會導致
func
函數值為負,你可以進一步擷取這些函數值,
並且使用本章其他訣竅技巧進行除錯。
使用
@@@
作用原函數可確認這些函數值均為負值。
討論說明
Reap
Sow
指令是威力強大的除錯工具,因為它們可以將資料擷取至任意數量的管道
中,使用
Sow
指令的第二個引數可以指定將資料放置於不同串列。例如,你想同時偵測
func
函數輸出為負值與零的情況,並放置於獨立的串列中。[Page-747]
ch19.indd 744 2014/4/2 下午 05:10:36
19.3 使用堆疊追蹤法對遞迴程式進行除錯
|
745
以下可看出這些串列中的引數具有不同的函數行為。
延伸資訊
訣竅 19.6 介紹
Reap
Sow
指令的另一個常見應用,用來對 Mathematica 內建數值演算
法或繪圖指令進行除錯。
訣竅 19.3 介紹如何使用
Reap
Sow
指令查看堆疊狀態。
19.3 使用堆疊追蹤法對遞迴程式
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Ubuntu for Non-Geeks, 4th Edition

Ubuntu for Non-Geeks, 4th Edition

Rickford Grant, Phil Bull

Publisher Resources

ISBN: 9789863470106