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 錦囊妙計
2.1 多引數函數映射(Mapping
|
35
Apply
指令也可接受第三個引數,用來指定
作用層數
level),此用法可以不用
Map
獲得相同的效用。[Page-034]
在此我們將
Plus
指令作用於層數
{1}
,這限制
Apply
指令僅作用於第一層元素。此處使
用了
預留位置序列
##
slot sequence),用來帶入所有的引數。因為這個用法很常見,
Mathematica 提供一個算符
@@@
直接達到此功能,用於此範例中,可進一步省略
##
而獲
得更簡潔的程式碼。
當你想要於函數中使用其他引數時,還是必須使用
##
,如以下範例:
下式表示於每一項總和中,再加一次第二個元素,即第二個元素被加了兩次。
使用以上的語法,我們可以獲得簡化版的折扣訂單總和。
若串列具較深層的巢狀結構,你可以指定較大的作用層數獲得所需結果。例如前例訂單
被置放於
envelope
額外結構下時:
綜合使用
Map
Apply
指令也可獲得相同結果,因為
Ma
p 指令也接受作用層數指定。
ch02.indd 35 2014/4/2 上午 03:31:59
36
|
第二章
當然,你也可以刪除
envelope
的包覆,這可以透過取出指定元素
[[All,2]]
達到,這語
法代表將第一層各元素的第二個元素取出。[Page-035]
以下程式僅使用
Map ...
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