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 錦囊妙計
196
|
第五章
延伸資訊
列, 串, 使
Select
StringMatchQ
作為模式匹配測試,而不是
StringCases
指令,詳見訣竅 4.1[Page-196]
5.4 字串複製
問題點
你想串接重複的字串為新字串。
解決方案
使用
StringJoin[]
指令串接字串串列。
ch05.indd 196 2014/4/2 上午 06:13:09
5.4 字串複製
|
197
討論說明
這個解法十分簡單,之所以將此問題納入本書,是因為你也許會覺得 Mathematica 應該
要為本功能提供內建指令,但事實上卻付之闕如。對於大多數應用實例,這個解法沒有
問題,但對於大數量的複製動作,另一個複製方法會更有效率。原理是以重複雙倍的動
作複製字串,直到大於指定數目且最接近 2 的冪次方,再擷取指定數目的字串數量。
n * StringLength[seed]
本方法可能有點難解,讓我們仔細看來。純函數
#<>#&
作用於字串串列會將字串複製
(回憶一下,
<>
算符用來串接字串)。[Page-197]
以下則會將字串複製兩次,也就是原字串的 4 倍。
重複進行此步驟
m
次,可以串接原字串的
2^m
倍,然而所需重複次數不見得
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