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 錦囊妙計
4.3 計算匹配模式的項目個數
|
153
以下提供了一個可同時得到
Cases
DeleteCases
結果的方式,而不必執行兩次樣式匹
配。[Page-155]
4.3 計算匹配模式的項目個數
問題點
你想知道表示式中匹配模式的項目數目為何,並想進一步指定作用層數。
解決方案
使用
Count
指令對整個表示式或特定的作用層數計算匹配模式的項目數目。
Count
最簡
單的用法應該是對指定的符號計數。
預設情況下,
Count
指令僅對第 1 層(即指定層數為
{1}
)項目計數,但也可於第 3 個引
數指定作用層數。
ch04.indd 153 2014/4/2 上午 05:39:03
154
|
第四章
Count
指令也可以用
Position
Cases
指令取代,當你已經對表示式進行模式比對時,
可以此方式計數。[Page-156]
討論說明
除了
Cases
,還有
LeafCount
Tally
等計數指令。使用
Count
指令模擬
LeafCount
的功
能是很困難的,這是因為
LeafCount
將複數以
FullForm
形式對待(例如對
Complex[1,1]
執行
LeafCount
指令將輸出 3),但即便使用
FullForm
形式,
Count
指令仍無法輸出相同
的結果。
你需要將複數以
ReplaceAll
指令消除,才能得到與
LeafCount ...
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