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 錦囊妙計
130
|
第三章
一般 Mathematica 程式設計師都會不假思索地以這個顯而易見的方式實作。然而這個
的(static), 的(dynamic),
Mathematica 而言這也不是問題,因為你可以隨時刪除 downvalue
11779 的關聯數值便消失了,此時 Mathematica 會回傳原表示式。
但這還 不夠,關聯 式資料 結構必 須能取出 所有鍵 值及對 應數值。當 然, 這也難 不倒
Mathematica[Page-131]
因此,所有的必備特性都可以使用 Mathematica 內建核心實作關聯式資料結構。剩下的
僅是將這些功能集中並定義統一使用方式。
討論說明
首先我們需要關聯數組的建構指令。如前文所提及的,我們以符號來解決此問題,至於
實作上符號的名稱並不重要,重要的是它必須是 Mathematica 內獨一無二的符號;很幸
運的,Mathematica 提供了
Unique
指令可建立獨特的符號;以此符號的 downvalue 建立
關聯數組,其起始狀態對所有鍵值均輸出空串列。此符號將被包裝在
Dictionary
標頭內
作為回傳值。
我們也需要一個方式刪除關聯數組及其所有內容,
Remove
指令可以達到這一點。
ch03.indd 130 2014/4/2 上午 05:19:25
3.13 善用 Mathematica 內建關聯查表功能
|
131
雖然前文提及其實沒有必要知道內部符號
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