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.6 對移動子串列進行函數映射
|
45
討論說明
前文闡述的是基本概念,但不易推廣,因為窗口大小與目標函數都固定在程式碼內。以
下提供可使用任意窗口大小與目標函數的指令。
事實上 Mathematica 內建有
MovingAverage
MovingMedian
指令可計算移動平均數與移
動中位數,其中
MovingAverage
也可指定權重。當你需要運算移動平均數與移動中位數
時,建議使用內建函數,它們能提供較佳的執行效率。
Mathematica 提供兩個特別指令:
ListConvolve
ListCorrelate
,用來進行更廣義的子
串列運算,它們的功能很多,花些時間深入了解是很值得的。以下只針對
ListConvolve
指令做介紹,因為這兩個指令在使用上相似,只是針對不同問題處理的方式不同。我們
就從移動平均數的計算介紹起。
ListConvolve
指令的第一個引數稱為
核心
kernel
),它是一個數字串列,用來定義子
串列的長度及權重,子串列將與核心相乘後再加總起來。以下使用符號使你更容易了解
運作。
此處使用簡單的核心
{1,1}
,其代表子串列的長度為 2,且每個元素會直接相加(因為
乘以 1 的結果仍不變),因此運算結果為連續子串列的和。只要將核心除以
n
便可得到
移動平均數。[Page-045]
這可輕易推廣至加權移動平均數,在此就不多做介紹了,畢竟 Mathematica 已提供了內
建指令。以下繼續討論
ListConvolve
指令。
ch02.indd 45 2014/4/2 上午 03:32:12 ...
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