• 沒有找到結果。

Introduction to Regular Expressions

N/A
N/A
Protected

Academic year: 2022

Share "Introduction to Regular Expressions"

Copied!
62
0
0

加載中.... (立即查看全文)

全文

(1)

Introduction to Regular Expressions

1

• A regular expression, also called a pattern, is an expression used to specify a set of strings required for a particular purpose.

Check this: https://regexone.com.

1See https://en.wikipedia.org/wiki/Regular_expression; also https://www.mathworks.com/help/matlab/matlab_prog/

regular-expressions.html.

Zheng-Liang Lu 202

(2)

Example

1 >> text = 'bat cat can car coat court CUT ct ...

CAT-scan';

2 >> pattern = 'c[aeiou]+t';

3 >> start idx = regexp(text, pattern)

4

5 start idx =

6

7 5 17

• The pattern ’c[aeiou]+t’ indicates a set of strings:

c must be the first character;

c must be followed by one of the characters in the brackets [aeiou], followed by t as the last character;

in particular, [aeiou] must occur one or more times, as indicated by the + operator.

Zheng-Liang Lu 203

(3)

Metacharacters

2

Operator Definition

| Boolean OR.

* 0 or more times consecutively.

? 0 times or 1 time.

+ 1 or more times consecutively.

{n} exactly n times consecutively.

{m, } at least m times consecutively.

{, n} at most n times consecutively.

{m, n} at least m times, but no more than n times consecutively.

2See https://www.mathworks.com/help/matlab/ref/regexp.html.

Zheng-Liang Lu 204

(4)

Operator Definition

. any single character, including white space.

[c1c2c3] any character contained within the brackets.

[∧c1c2c3] any character not contained within the brackets.

[c1-c2] any character in the range of c1 through c2.

\s any white-space character.

\w a word; any alphabetic, numeric, or underscore character.

\W not a word.

\d any numeric digit; equivalent to [0-9].

\D no numeric digit; equivalent to [∧0-9].

Zheng-Liang Lu 205

(5)

Output Keywords

Keyword Output

’start’ starting indices of all matches, by default

’end’ ending indices of all matches

’match’ text of each substring that matches the pattern

’tokens’ text of each captured token

’split’ text of nonmatching substrings

’names’ name and text of each named token

Zheng-Liang Lu 206

(6)

Examples

1 clear; clc;

2

3 text1 = {'Madrid, Spain', 'Romeo and Juliet', ...

'MATLAB is great'};

4 tokens = regexp(text1, '\s', 'split')

5

6 text2 = 'EXTRA! The regexp function helps you ...

relax.';

7 matches = regexp(text2, '\w*x\w*', 'match')

Zheng-Liang Lu 207

(7)

Exercise: Listing Filtered Files

1 clear; clc;

2

3 file list = dir;

4 filenames = {file list(:).name};

5 A = regexp(filenames, '.+\.m', 'match');

6 mask = cellfun(@(x) ~isempty(x), A);

7 cellfun(@(f) fprintf('%s\\%s\n', pwd, f{:}), A(mask))

Zheng-Liang Lu 208

(8)

Example: By Names

• You can associate names with tokens so that they are more easily identifiable.

• For example,

1 >> str = 'Here is a date: 01-Apr-2020';

2 >> expr = '(?<day>\d+)-(?<month>\w+)-(?<year>\d+)';

3 >> mydate = regexp(str, expr, 'names')

4

5 mydate =

6

7 day: '01'

8 month: 'Apr'

9 year: '2020'

Zheng-Liang Lu 209

(9)

Exercise: Web Crawler

• Write a script which collects the names of html tags by defining a token within a regular expression.

• For example,

1 >> str = '<title>My Title</title><p>Here is some ...

text.</p>';

2 >> pattern = '<(\w+).*>.*</\1>';

3 >> [tokens, matches] = regexp(str, pattern, ...

'tokens', 'match')

Zheng-Liang Lu 210

(10)

More Regexp Functions

• See regexpi, regexprep, and regexptranslate.

Zheng-Liang Lu 211

(11)

1 >> Lecture 6

2 >>

3 >> -- Special Topic: File Operations & other I/O

4 >>

Zheng-Liang Lu 212

(12)

Spreadsheets: Excel/CSV Files (Revisited)

• The command xlsread(filename) reads excel files, for example,

1 [~, ~, raw] = xlsread("2330.xlsx");

• By default, it returns a numeric matrix.

• The text part is the 2nd output, separated from the numeric part.

• You may consider the whole spreadsheet by using the 3rd output (stored in a cell array).

• Note that you can use ∼ to drop the output value.

Zheng-Liang Lu 213

(13)

More Tips for Excel Files

• You can specify the range.

For example, the string argument"B:B"is used to import column B.

If you need a single value, say the cell B1, just use"B1:B1".3

• You could specify the worksheet by the sheet name4 or the sheet number.

• You could refer to the document for more details.5

3Contribution by Mr. Tsung-Yu Hsieh (MAT24409) on August 27, 2014.

4The default sheet name is “工作表”.

5See https://www.mathworks.com/help/matlab/ref/xlsread.html.

Zheng-Liang Lu 214

(14)

Mat Files

6

• Recall that I/O is costly.

• To save time, you may consider save matrices to the disk; for example,

1 data1 = rand(1, 10);

2 data2 = ones(10);

3 save('trial.mat', 'data1', 'data2');

• You can use load to fetch the data from mat files.

1 load('trial.mat');

6See https://www.mathworks.com/help/matlab/ref/save.html.

Zheng-Liang Lu 215

(15)

Selected Read/Write Functions

• For text data, see https:

//www.mathworks.com/help/matlab/text-files.html.

Try dlmread, dlmwrite, csvread, csvwrite, textread/textscan.

• For images, see https://www.mathworks.com/help/

matlab/images_images.html.

• For video and audio, see https://www.mathworks.com/

help/matlab/audio-and-video.html.

Zheng-Liang Lu 216

(16)

Selected File Operations

7

cd Change current folder.

pwd Identify current folder.

ls List folder contents by chars.

dir List folder contents by structures.

exist Check existence of variable, script, function, folder, or class.

mkdir Make new folder.

visdiff Compare two files or folders.

7See

https://www.mathworks.com/help/matlab/file-operations.html.

Zheng-Liang Lu 217

(17)

Example: Pooling Data from Multiple Files

8

1 clear; clc;

2

3 cd('./stocks'); % enter the folder

4 files = dir; % get all files in the current folder

5 files = files(3 : end); % drop the first two

6 names = {files(:).name}; % get all file names

7 filter = endsWith(names, '.xlsx'); % filter by .xlsx

8 names = names(filter);

9

10 pool = cell(length(names), 2);

11 for i = 1 : length(names)

12 [~, ~, raw] = xlsread(names{i});

13 pool(i, :) = {names{i}(1 : 4), raw};

14 end

15 save('data pool', 'pool');

8Downloadstocks.zip.

Zheng-Liang Lu 218

(18)

1 >> Lecture 7

2 >>

3 >> -- Matrix Computation

4 >>

Zheng-Liang Lu 219

(19)

Vectors

• Let R be the set of all real numbers.

• Rn denotes the vector space of all m-by-1 column vectors:

u = (ui) =

 u1

... um

. (1)

You can simply use the colon (:) operator to reshape any array in a column major, say u(:).

• Similarly, the row vector v is v = (vi) =

v1· · · vn  . (2)

• We consider column vectors unless stated.

Zheng-Liang Lu 220

(20)

Matrices

• Mm×n(R) denotes the vector space of all m-by-n real matrices, for example,

A = (aij) =

a11 · · · a1n ... . .. ... am1 · · · amn

.

• Complex vectors/matrices9 follow similar definitions and operations introduced later, simply with some care.

9Matlab treats a complex number as a single value.

Zheng-Liang Lu 221

(21)

Transposition

1 >> A = [1 i];

2 >> A' % Hermitian operator; see any textbook for ...

linear algebra

3

4 ans =

5

6 1.0000 + 0.0000i

7 0.0000 - 1.0000i

8

9 >> A.' % transposition of A

10

11 ans =

12

13 1.0000 + 0.0000i

14 0.0000 + 1.0000i

Zheng-Liang Lu 222

(22)

Arithmetic Operations

• Let aij and bij be the elements of the matrices A and B ∈ Mm×n(R) for 1 ≤ i ≤ m and 1 ≤ j ≤ n.

• Then C = A ± B can be calculated by cij = aij ± bij. (Try.)

Zheng-Liang Lu 223

(23)

Inner Product

10

• Let u, v ∈ Rm.

• Then the inner product, denoted by u · v , is calculated by

u · v = u0v = [u1· · · um]

 v1

... vm

.

1 clear; clc;

2

3 u = [1; 2; 3];

4 v = [4; 5; 6];

5 u' * v % normal way; orientation is important

6 dot(u, v) % using the built-in function

10Akaa dot product and scalar product.

Zheng-Liang Lu 224

(24)

• Inner product is also calledprojection for emphasizing its geometric significance.

• Recall that we know

u · v = 0

if and only if these two are orthogonal to each other, denoted by

u ⊥ v .

Zheng-Liang Lu 225

(25)

Generalization of Inner Product

• Let x ∈ R, f (x) and g (x) be real-valued functions.

• In particular, assume that g (x ) is a basis function.11

• Then we can define the inner product of f and g on [a, b] by

hf , g i = Z b

a

f (x )g (x )dx .

11See https://en.wikipedia.org/wiki/Basis_function, https://en.wikipedia.org/wiki/Eigenfunction, and https://en.wikipedia.org/wiki/Approximation_theory.

Zheng-Liang Lu 226

(26)

• For example,Fourier transformis widely used in engineering and science.

Fourier integral12 is defined as

F (ω) = Z

−∞

f (t)e−i ωtdt

where f (t) is a square-integrable function.

The Fast Fourier transform (FFT) algorithm computes the discrete Fourier transform (DFT) in O(n log n) time.13,14

12See https://en.wikipedia.org/wiki/Fourier_transform.

13Cooley and Tukey (1965).

14See https://en.wikipedia.org/wiki/Fast_Fourier_transform.

Zheng-Liang Lu 227

(27)

Matrix Multiplication

• Let A ∈ Mm×q(R) and B ∈ Mq×n(R).

• Then C = AB is given by

cij =

q

X

k=1

aik× bkj. (3)

• For example,

Zheng-Liang Lu 228

(28)

Example

1 clear; clc;

2

3 A = randi(10, 5, 4); % 5-by-4

4 B = randi(10, 4, 3); % 4-by-3

5 C = zeros(size(A, 1), size(B, 2));

6 for i = 1 : size(A, 1)

7 for j = 1 : size(B, 2)

8 for k = 1 : size(A, 2)

9 C(i, j) = C(i, j) + A(i, k) * B(k, j);

10 end

11 end

12 end

13 C % display C

• Time complexity: O(n3).

• Strassen (1969): O(nlog27).

Zheng-Liang Lu 229

(29)

Matrix Exponentiation

• Raising a matrix to a power is equivalent to repeatedly multiplying the matrix by itself.

For example, A2= AA.

• The matrix exponential15is a matrix function on square matrices analogous to the ordinary exponential function, more explicitly,

eA=

X

n=0

An n!.

• However, it is not allowedto perform AB.

15Seematrix exponentialsandPauli matrices.

Zheng-Liang Lu 230

(30)

Determinants

• Consider the matrix

A =a b c d

 .

• Then det(A) = ad − bc is called the determinant of A.

The method of determinant calculation in high school is a wrong way but produces correct answers for all 3 × 3 matrices.

• Let’s try the minor expansion formula for det(A).16

16See http://en.wikipedia.org/wiki/Determinant.

Zheng-Liang Lu 231

(31)

Recursive Algorithm for Minor Expansion Formula

1 function y = myDet(A)

2

3 [r, ~] = size(A);

4

5 if r == 1

6 y = A;

7 elseif r == 2

8 y = A(1, 1) * A(2, 2) - A(1, 2) * A(2, 1);

9 else

10 y = 0;

11 for i = 1 : r

12 B = A(2 : r, [1 : i - 1, i + 1 : r]);

13 cofactor = (-1) ˆ (i + 1) * myDet(B);

14 y = y + A(1, i) * cofactor;

15 end

16 end

17 end

Zheng-Liang Lu 232

(32)

• It needs n! terms in the sum of products, so this algorithm runs in O(n!) time!

• Use det for determinants, which can be done in O(n3) time by using LU decomposition or alike.17

17See https://en.wikipedia.org/wiki/LU_decomposition. Moreover, various decompositions are used to implement efficient matrix algorithms in numerical analysis. See

https://en.wikipedia.org/wiki/Matrix_decomposition.

Zheng-Liang Lu 233

(33)

Linear Systems (Transformation/Mapping)

18

• A linear system is a mathematical model of a system based on linear operators satisfying the property of superposition.

For simplicity, Ax = y for any input x associated with the output y .

Then A is alinear operatorif and only if

A(ax1+ bx2) = aAx1+ bAx2= ay1+ by2

for a, b ∈ R.

For example, d (x2dx+3x ) = dxdx2 + 3dxdx = 2x + 3.

• Linear systems typically exhibit features and properties that are much simpler than the nonlinear case.

What about nonlinear cases?

18See https://en.wikipedia.org/wiki/Linear_system.

Zheng-Liang Lu 234

(34)

First-Order Approximation: Local Linearization

• Let f (x ) be any nonlinear function.

• Assume that f (x ) is infinitely differentiable at x0.

• By Taylor’s expansion19, we have

f (x ) = f (x0) + f0(x0)(x − x0) + O (x − x0)2 , where O (x − x0)2 is the collection of higher-order terms, which can be neglected as x − x0 → 0.

• Then we have a first-order approximation f (x ) ≈ f0(x0)x + k, with k = f (x0) − x0f0(x0), a constant.

19See https://en.wikipedia.org/wiki/Taylor_series.

Zheng-Liang Lu 235

(35)

Two Observations

• We barely feel like the curvature of the ground; however, we look at Earth on the moon and agree that Earth is a sphere.

• Newton’s kinetic energy is a low-speed approximation (classical limit) to Einstein’s total energy.

Let m be the rest mass and v be the velocity relative to the inertial coordinate.

The resulting total energy is

E = mc2

p1 − (v/c)2.

By applying the first-order approximation,

E ≈ mc2+1 2mv2.

Zheng-Liang Lu 236

(36)

Example: Kirchhoff’s Laws

20

• The algebraic sum of currents in a network of conductors meeting at a point is zero.

• The directed sum of the potential differences (voltages) around any closed loop is zero.

20See https://en.wikipedia.org/wiki/Kirchhoff’s_circuit_laws.

Zheng-Liang Lu 237

(37)

General Form of Linear Equations

21

• Let n be the number of unknowns and m be the number of constraints.

• A general system of m linear equations with n unknowns is









a11x1 +a12x2 · · · +a1nxn = y1 a21x1 +a22x2 · · · +a2nxn = y2

... ... . .. ... = ... am1x1 +am2x2 · · · +amnxn = ym where x1, . . . , xn are unknowns, a11, . . . , amn are the coefficientsof the system, and y1, . . . , ym are theconstant terms.

21See https://en.wikipedia.org/wiki/System_of_linear_equations.

Zheng-Liang Lu 238

(38)

Matrix Equation

• Hence we can rewrite the aforesaid equations as follows:

Ax = y . where

A =

a11 a12 · · · a1n

a21 a22 · · · a2n ... ... . .. ... am1 am2 · · · amn

 ,

x =

 x1

... xn

, and y =

 y1

... ym

.

• Finally, x can be done by x = A−1y , where A−1 is called the inverse of A.

Zheng-Liang Lu 239

(39)

Inverse Matrices

22

• For simplicity, let A ∈ Mn×n(R) and x, y ∈ Rn.

• Then A is called invertible if there exists B ∈ Mn×n(R) such that

AB = BA = In, where In denotes a n × n identity matrix.

We use A−1 to denote the inverse of A.

You can use eye(n) to generate an identity matrix In.

• Use inv(A) to calculate the inverse of A.

22See https://en.wikipedia.org/wiki/Invertible_matrix#The_

invertible_matrix_theorem.

Zheng-Liang Lu 240

(40)

• However, inv(A) may return a weird result even if A is ill-conditioned, indicates how much the output value of the function can change for a small change in the input

argument.23

• For example, calculate the inverse of the matrix

A =

1 2 3 4 5 6 7 8 9

.

Recall the Cramer’s rule24: A is invertible iff det(A) 6= 0.

(Try.)

• If these constraints cannot be eliminated by row reduction, they are linearly independent.

23You may refer to thecondition numberof a function with respect to an argument. Also try rcond.

24See https://en.wikipedia.org/wiki/Cramer’s_rule.

Zheng-Liang Lu 241

(41)

Linear Independence

• Let K = {a1, a2, . . . , an} for each ai ∈ Rm.

• Now consider this linear superposition

x1a1+ x2a2+ · · · + xnan= 0, where x1, x2, . . . , xn∈ R are the weights.

• Then K islinearly independent iff

x1 = x2= · · · = xn= 0.

Zheng-Liang Lu 242

(42)

Example: R

3

• Let

K1=

 1 0 0

,

 0 1 0

,

 0 0 1

 .

• It is clear that K1 is linearly independent.

• Moreover, you can represent all vectors in R3 if you collect all linear superpositions from K1.

• We call this new set a spanof K1, denoted by Span(K1).25

• Clearly, Span(K1) = R3.

25See https://en.wikipedia.org/wiki/Linear_span.

Zheng-Liang Lu 243

(43)

• Now let

K2=

 1 0 0

,

 0 1 0

,

 0 0 1

,

 1 2 3

 .

• Then K2 is not a linearly independent set. (Why?)

• If you takeone or more vectors out of K2, then K2 becomes linearly independent.

Zheng-Liang Lu 244

(44)

Basis of Vector Space & Its Dimension

26

• However, you can take only one vector out of K2 if you want to represent all vectors in R3. (Why?)

Thedimensionof R3 is exactly the size (element number) of K2.

• We say thatthe basis of Rn is a maximally linearly independent set of size n.

• Note that the basis of R3 is not unique.

For example, K1 could be also a basis of R3.

26See https://en.wikipedia.org/wiki/Basis_(linear_algebra), https://en.wikipedia.org/wiki/Vector_space, and

https://en.wikipedia.org/wiki/Dimension_(vector_space).

Zheng-Liang Lu 245

(45)

Linear Transformation (Revisited)

27

27See https://en.wikipedia.org/wiki/Linear_map; also see https://kevinbinz.com/2017/02/20/linear-algebra/.

Zheng-Liang Lu 246

(46)

Example: Vector Projection (R

3

→ R

2

)

• Let u ∈ R3 and v ∈ R2.

• We consider the projection matrix (operator),

A =1 0 0 0 1 0



so that Au = v .

• For example,

1 0 0 0 1 0



 1 2 3

=1 2

 .

Zheng-Liang Lu 247

(47)

Solution Set to System of Linear Equations

28

• Recall that m is the number of constraints and n is the number of unknowns.

• Now consider the following cases.

• Ifm = n, then there exists a uniquesolution.

• Ifm > n, then it is called an overdetermined system and there is no solution.

Fortunately, we can find aleast-squares error solutionsuch that k Ax − y k2is minimal, shown later.

• Ifm < n, then it is called a underdetermined system which hasinfinitely many solutions.

Become an optimization problem?

• For all cases,

x = A \ y .

28See https://www.mathworks.com/help/matlab/ref/mldivide.html.

Zheng-Liang Lu 248

(48)

Case 1: m = n

• For example,

3x + 2y − z = 1

x − y + 2z = −1

−2x + y − 2z = 0

1 >> A = [3 2 -1; 1 -1 2; -2 1 -2];

2 >> b = [1; -1; 0];

3 >> x = A \ b

4

5 1

6 -2

7 -2

Zheng-Liang Lu 249

(49)

Case 2: m > n

• For example,

2x − y = 2

x − 2y = −2

x + y = 1

1 >> A = [2 -1; 1 -2; 1 1];

2 >> b = [2; -2; 1];

3 >> x = A \ b

4

5 1

6 1

Zheng-Liang Lu 250

(50)

Case 3: m < n

• For example,

 x + 2y + 3z = 7

4x + 5y + 6z = 8

1 >> A = [1 2 3; 4 5 6];

2 >> b = [7; 8];

3 >> x = A \ b

4

5 -3

6 0

7 3.333

• Note that this solution is a basic solution, one of infinitely many.

• How to find the directional vector? (Try cross.)

Zheng-Liang Lu 251

(51)

Gaussian Elimination Algorithm

29

• First we consider the linear system is represented as an augmented matrix [ A | y ].

• We then transform A into an upper triangular matrix

[ ¯A | y ] =

1 a¯12 · · · a¯1n1 0 1 · · · a¯2n2

... ... . .. ... ... 0 0 · · · 1 y¯n

 .

where ¯aij’s and ¯yi’s are the resulting values after elementary row operations.

• This matrix is said to be in reduced row echelon form.

29See https://en.wikipedia.org/wiki/Gaussian_elimination.

Zheng-Liang Lu 252

(52)

• The solution can be done by backward substitution:

xi = ¯yi

n

X

j =i +1

¯ aijxj,

where i = 1, 2, · · · , n.

• Time complexity: O(n3).

Zheng-Liang Lu 253

(53)

Exercise

1 clear; clc;

2

3 A = [3 2 -1; 1 -1 2; -2 1 -2];

4 b = [1; -1; 0];

5 A \ b % check the answer

6

7 for i = 1 : 3

8 for j = i : 3

9 b(j) = b(j) / A(j, i); % why first?

10 A(j, :) = A(j, :) / A(j, i);

11 end

12 for j = i + 1 : 3

13 A(j, :) = A(j, :) - A(i, :);

14 b(j) = b(j) - b(i);

15 end

16 end

17 x = zeros(3, 1);

Zheng-Liang Lu 254

(54)

18 for i = 3 : -1 : 1

19 x(i) = b(i);

20 for j = i + 1 : 1 : 3

21 x(i) = x(i) - A(i, j) * x(j);

22 end

23 end

24 x

Zheng-Liang Lu 255

(55)

Selected Functions of Linear Algebra

30

• Matrix properties: norm, null, orth, rank, rref, trace, subspace.

• Matrix factorizations: lu, chol, qr.

30See https://www.mathworks.com/help/matlab/linear-algebra.html.

Zheng-Liang Lu 256

(56)

Numerical Example: 2D Laplace’s Equation

• A partial differential equation (PDE) is a differential equation that contains unknown multivariable functions and their partial derivatives.31

• Let Φ(x , y ) be a scalar field on R2.

• Consider Laplace’s equation32as follows:

2Φ(x , y ) = 0,

where ∇2 = ∂x22 +∂y22 is the Laplace operator.

• Consider the system shown in the next page.

31See

https://en.wikipedia.org/wiki/Partial_differential_equation.

32Pierre-Simon Laplace (1749–1827).

Zheng-Liang Lu 257

(57)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0

0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

V1 V2 V3 V4 V5

V6 V7 V8 V9 V10

V11 V12 V13 V14 V15

V16 V17 V18 V19 V20

V21 V22 V23 V24 V25

• Consider theboundary condition:

V1= V2= · · · = V4= 0.

V21= V22= · · · = V24= 0.

V1= V6= · · · = V16= 0.

V5= V10= · · · = V25= 1.

Zheng-Liang Lu 258

(58)

An Simple Approximation

33

• As you can see, we partition the region into many subregions by applying a proper mesh generation.

• Then Φ(x , y ) can be approximated by

Φ(x , y ) ≈ Φ(x + h, y ) + Φ(x − h, y ) + Φ(x , y + h) + Φ(x , y − h)

4 ,

where h is small enough.

33See

https://en.wikipedia.org/wiki/Finite_difference_method#Example:

_The_Laplace_operator.

Zheng-Liang Lu 259

(59)

Matrix Formation

• By collecting all constraints, we have Ax = b where

A =

4 −1 0 −1 0 0 0 0 0

−1 4 −1 0 −1 0 0 0 0

0 −1 4 0 0 −1 0 0 0

−1 0 0 4 −1 0 −1 0 0

0 −1 0 −1 4 −1 0 −1 0

0 0 −1 0 −1 4 −1 0 −1

0 0 0 −1 0 0 4 −1 0

0 0 0 0 −1 0 −1 4 −1

0 0 0 0 0 −1 0 −1 4

and

b =

0 0 1 0 0 1 0 0 1 T

.

Zheng-Liang Lu 260

(60)

Dimension Reduction by Symmetry

• As you can see, V7= V17, V8 = V18 and V9 = V19.

• So we can reduce A to A0

A0 =

4 −1 0 −1 0 0

−1 4 −1 0 −1 0

0 −1 4 0 0 −1

−2 0 0 4 −1 0

0 −2 0 −1 4 −1

0 0 −2 0 −1 4

and

b0=

0 0 1 0 0 1 T

.

• The dimensions of this problem are cut to 6 from 9.

• This trick helps to alleviate the curse of dimensionality.34

34See https://en.wikipedia.org/wiki/Curse_of_dimensionality.

Zheng-Liang Lu 261

(61)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0

0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

V1 V2 V3 V4 V5

V6 V7 V8 V9 V10

V11 V12 V13 V14 V15

V16 V17 V18 V19 V20

V21 V22 V23 V24 V25

0.0000 0.0000 0.0000 0.0000 1.0000

0.0000 0.0714 0.1875 0.4286 1.0000

0.0000 0.0982 0.2500 0.5268 1.0000

0.0000 0.0714 0.1875 0.4286 1.0000

0.0000 0.0000 0.0000 0.0000 1.0000

Zheng-Liang Lu 262

(62)

Remarks

• This is a toy example for numerical methods of PDEs.

• We can use the PDE toolbox for this case. (Try.)

You may consider thefinite element method(FEM).35

The mesh generation is also crucial for numerical methods.36

You can use the Computational Geometry toolbox for triangular mesh.37

35See https://en.wikipedia.org/wiki/Finite_element_method.

36See https://en.wikipedia.org/wiki/Mesh_generation.

37See https:

//www.mathworks.com/help/matlab/computational-geometry.html.

Zheng-Liang Lu 263

參考文獻

相關文件

[This function is named after the electrical engineer Oliver Heaviside (1850–1925) and can be used to describe an electric current that is switched on at time t = 0.] Its graph

• An algorithm for such a problem whose running time is a polynomial of the input length and the value (not length) of the largest integer parameter is a..

• If we know how to generate a solution, we can solve the corresponding decision problem.. – If you can find a satisfying truth assignment efficiently, then sat is

• By definition, a pseudo-polynomial-time algorithm becomes polynomial-time if each integer parameter is limited to having a value polynomial in the input length.. • Corollary 42

(In Section 7.5 we will be able to use Newton's Law of Cooling to find an equation for T as a function of time.) By measuring the slope of the tangent, estimate the rate of change

Let f being a Morse function on a smooth compact manifold M (In his paper, the result can be generalized to non-compact cases in certain ways, but we assume the compactness

• When a system undergoes any chemical or physical change, the accompanying change in internal energy, ΔE, is the sum of the heat added to or liberated from the system, q, and the

If x or F is a vector, then the condition number is defined in a similar way using norms and it measures the maximum relative change, which is attained for some, but not all