Skip to Content
Mathematica 錦囊妙計
book

Mathematica 錦囊妙計

by Sal Mangano
April 2014
Beginner to intermediate
830 pages
15h 21m
Chinese
GoTop Information, Inc.
Content preview from Mathematica 錦囊妙計
148
|
第四章
Rules(規則式)
規則式把模式匹配的功能帶到了新的層次,它用來對匹配表示式進行轉換,規則式整
合 在 Mathematica 的 核 心, 用 來 表 示 方 程 式 的 解( 見 訣 竅 11.6)、 指 令 選 項
Options
的 使 用( 見 訣 竅 2.17) 與 稀 疏 矩 陣
SparseArrays
的 定 義( 見 訣 竅 3.8),
Rules
也 是
Mathematica 的符號功能的基礎。每位 Mathematica 使用者都不應忽略。[Page-150]
將符合模式的位元串列轉換為整數,使用 RuleDelayed 指令是因為 b 在匹配之前並沒有定義
以 Pi 數值取代每個 x
想了解
->
與
:>
的差異有個不錯的方式,參考下以的亂數取代規則式。
→ 的方式在匹配時會馬上計算,因此取代結果均為相同數值
:→
的方式會在每次達成匹配時均重新計算
延伸資訊
Mathematica 教學文件
tutorial/PatternsAndTransformationRules
提供了絕佳的學習資源,
詳加閱讀將可顯著加強 Mathematica 程式功力。
4.1 取出匹配(或不匹配)模式的元素
問題點
你想取出串列或表示式中匹配模式的項目,找出這些項目同時也希望對其進行轉換。
ch04.indd 148 2014/4/2 上午 05:39:00
4.1 取出匹配(或不匹配)模式的元素
|
149
解決方案
使用
Cases
取出串列或表示式中匹配模式的項目。[Page-151]
使用規則式
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.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Mathematica Cookbook

Mathematica Cookbook

Sal Mangano

Publisher Resources

ISBN: 9789863470106