Upload
others
View
1
Download
0
Embed Size (px)
Citation preview
Basic Numerical TechniquesComputational Electromagnetics
Basic Numerical Techniques
Outline
Introduction
Numerical Integration
Random Number Generation
Monte Carlo Methods
Conclusion
Basic Numerical Techniques
Some useful tools in CEM
Numerical Integration
I Computing elements of coupling matrix in method of moments
I Near-field to far-field transformations (radiated fields)
I Computing charge and current in FD and FEM methods
Random Number Generation
I Non-uniform random variables
Monte Carlo Analysis
I Statistical analysis of arbitrary systems
Basic Numerical Techniques
Outline
Introduction
Numerical Integration
Random Number Generation
Monte Carlo Methods
Conclusion
Basic Numerical Techniques
Numerical Integration
Goal is to compute
I =
∫ b
af (x)dx ≈
N∑i=1
ci f (xi ). (1)
I This kind of approximation is called numerical quadrature.
I Several methods exist for choosing the xi and ci .
Basic Numerical Techniques
Uniform Sampling
I Sample interval from a to b uniformly
I Form subintervals
I Approximate f (x) with nth order polynomial
I Closed formulas (use endpoints) open formulas (don’t)
Midpoint Rule
f(x)
x2 xN. . .
∆x
xx1 ba
i = 1, . . . ,N, (2)
xi = (i − 1
2)∆x + a, ∆x =
b − a
N(3)
ci = ∆x . (4)
Basic Numerical Techniques
Higher-order Rules
Trapezoidal Rule
f(x)
. . .
∆x
xxN = ba = x1
xi = (i − 1)∆x + a, (5)
∆x =b − a
N − 1(6)
ci = 0.5, 1, 1, . . . , 1, 0.5∆x . (7)
Simpson’s Rule
xi = (i − 1)∆x + a, (8)
∆x =b − a
N − 1(9)
ci = 1, 4, 2, 4, 2, . . . , 2, 4, 1∆x
3. (10)
Basic Numerical Techniques
Higher-order Rules
Trapezoidal Rule
f(x)
. . .
∆x
xxN = ba = x1
xi = (i − 1)∆x + a, (5)
∆x =b − a
N − 1(6)
ci = 0.5, 1, 1, . . . , 1, 0.5∆x . (7)
Simpson’s Rule
xi = (i − 1)∆x + a, (8)
∆x =b − a
N − 1(9)
ci = 1, 4, 2, 4, 2, . . . , 2, 4, 1∆x
3. (10)
Basic Numerical Techniques
Newton-Cotes Rules
I Generalization of other rules
I Subdivide total interval: equal-length sub-intervals
I Approximate contribution of each subinterval with∫ b′
a′f (x)dx ≈ ∆x
n∑i=0
c(n)i f (xi ). (11)
Basic Numerical Techniques
Newton-Cotes Rules
∆x
f(x)
xb′ = x
na′ = x0
f (x) ≈ g(x) =n∑
i=0
f (xi )n∏
j=0,j 6=i
x − xj
xi − xj︸ ︷︷ ︸Pi (x)
.
(12)
Product term Pi (x) is an interpolating polynomial
Pi (x) =
1, x = xi
0, x = xk , k 6= i .(13)
Basic Numerical Techniques
Newton-Cotes Rules
∆x
f(x)
xb′ = x
na′ = x0
f (x) ≈ g(x) =n∑
i=0
f (xi )n∏
j=0,j 6=i
x − xj
xi − xj︸ ︷︷ ︸Pi (x)
.
(12)
Product term Pi (x) is an interpolating polynomial
Pi (x) =
1, x = xi
0, x = xk , k 6= i .(13)
Basic Numerical Techniques
Newton-Cotes Rules
∆x
f(x)
xb′ = x
na′ = x0
Uniform sampling: xi = i∆x + a′, ∆x = (b′ − a′)/n
Pi (x) =∏
j=0,j 6=i
x − j∆x − a′
i∆x − j∆x=
∏j=0,j 6=i
s − j
i − j= Li (s), (14)
where s = (x − a′)/∆x .
Basic Numerical Techniques
Example Interpolating Polynomials
Li (s) =∏
j=0,j 6=i
s − j
i − j
0 0.5 1 1.5 2−0.2
0
0.2
0.4
0.6
0.8
1
s
Li(s
)
L0
L1
L2
0 0.5 1 1.5 2 2.5 3−0.4
−0.2
0
0.2
0.4
0.6
0.8
1
1.2
s
Li(s
)
L0
L1
L2
L3
Basic Numerical Techniques
Newton-Cotes: Integration
Since g(x) is now an nth order polynomial, we can integrate itdirectly: ∫ b′
a′g(x)dx =
∫ b′
a′
n∑i=0
f (xi )Li (s)dx (15)
=n∑
i=0
f (xi )
∫ b′
a′Li (s)dx (16)
= ∆xn∑
i=0
f (xi )
∫ n
0Li (s)ds︸ ︷︷ ︸c
(n)i
. (17)
From before
∫ b′
a′f (x)dx ≈ ∆x
n∑i=0
c(n)i f (xi ). (18)
Basic Numerical Techniques
Example: Newton-Cotes (n = 2)
Applying c(n)i =
∫ n0 Li (s)ds, Li (s) =
∏j=0,j 6=i
s−ji−j
c(2)0 =
∫ 2
0
s − 1
−1
s − 2
−2ds =
1
3(19)
c(2)1 =
∫ 2
0
s
1
s − 2
−1ds =
4
3(20)
c(2)2 =
∫ 2
0
s
2
s − 1
1ds =
1
3(21)
leading to ∫ b′
a′f (x)dx ≈ ∆x
3[f (x0) + 4f (x1) + f (x2)]. (22)
This is just Simpson’s rule on each sub-interval.
Basic Numerical Techniques
Gaussian Quadrature
∫ b
aw(x)f (x)dx ≈
∑i
wi f (xi ), (23)
I Non-uniform sampling
I w(x) is a weighting function
I xi are chosen to be the zeros of an orthogonal polynomialdefined on (a, b)
I Advantages:I Can accommodate cases where a and/or b are infiniteI Exact if function is polynomial of degree 2n − 1 or less
(Maximum accuracy for fixed number of points)
I Disadvantages:I Complexity of non-uniform samplingI More difficult to compute xi
Basic Numerical Techniques
Multi-dimensional Integration
I Natural extension of 1D rules
I Given the rule ∫ b
af (x)dx ≈
N∑i=1
ci f (xi ), (24)
I Can extend to 2D using∫ bx
ax
∫ by
ay
f (x , y)dy dx ≈Nx∑i=1
Ny∑j=1
cx ,icy ,j︸ ︷︷ ︸cij
f (xi , yj). (25)
Basic Numerical Techniques
Outline
Introduction
Numerical Integration
Random Number Generation
Monte Carlo Methods
Conclusion
Basic Numerical Techniques
Random Number Generation
I MATLAB/C: Can produce uniform RV on [0,1]
I What if we need other non-uniform RVs?I Two basic methods:
I Inverse methodI Rejection method
Basic Numerical Techniques
Inverse Method
I CDF of RV X is Fx(x) = Pr X ≤ xI Inverse method requires F−1
x (x)
I Let U = Fx(X )
Fu(u) = Pr U ≤ u (26)
= Pr Fx(X ) ≤ u (27)
= PrX ≤ F−1
x (u)
(28)
= Fx [F−1x (u)] (29)
= u. (30)
I Observation: X can be anything, but U always uniform!
I Method: Generate U ∼ U[0, 1], X = F−1x (U)
Basic Numerical Techniques
Inverse Method
I CDF of RV X is Fx(x) = Pr X ≤ xI Inverse method requires F−1
x (x)
I Let U = Fx(X )
Fu(u) = Pr U ≤ u (26)
= Pr Fx(X ) ≤ u (27)
= PrX ≤ F−1
x (u)
(28)
= Fx [F−1x (u)] (29)
= u. (30)
I Observation: X can be anything, but U always uniform!
I Method: Generate U ∼ U[0, 1], X = F−1x (U)
Basic Numerical Techniques
Inverse Method: Example
Rayleigh Distribution
f (x) =x
σ2e−
x2
2σ2 (31)
Fx(x) = 1− e−x2
2σ2 = u (32)
x = F−1x (u) =
√−2σ2 ln(1− u) (33)
We can generate uniform random variables U ∼ U[0, 1] and pluginto the equation above to get variables X that are Rayleighdistributed.
Basic Numerical Techniques
Rejection Method
What happens if we can’t get inverse CDF? Can use rejectionmethod.
PDF of Random Variable
xa b
y
fx(x)
ymax
Compute
U1 ∼ U[0, 1] (34)
U2 ∼ U[0, 1] (35)
and
X1 = a + U1(b − a) (36)
Y1 = ymaxU2 (37)
I Y1 ≤ fx(X1), declareX = X1.
I If not, reject and try again.
Basic Numerical Techniques
Rejection Method: How it works
I Find PDF of X1 under the assumption that X1 is not rejected
I Let R be RV: R = 0 (not rejected) and R = 1 (rejected)
I Conditional PDF on rejection indicator
f (x1|r) =f (r |x1)f (x1)
f (r)(38)
f (x1|r = 0) =Pr R = 0|X1 = x1 f (x1)
Pr R = 0(39)
=Pr Y1 ≤ fx(X1)|X1 = x1 f (x1)
Pr Y1 ≤ fx(X1)(40)
=Pr Y1 ≤ fx(x1) f (x1)
Pr Y1 ≤ fx(X1). (41)
Basic Numerical Techniques
Rejection Method: How it works (cont’d)
f (x1|r = 0) =Pr Y1 ≤ fx(x1) f (x1)
Pr Y1 ≤ fx(X1)
xa b
y
fx(x)
ymax
Pr Y1 ≤ fx(x1) =Height to fx(x1)
Total height=
fx(x1)
ymax(42)
Pr Y1 ≤ fx(X1) =PDF area
Uniform box area=
1
(b − a)ymax(43)
f (x1) = Uniform PDF on [a,b] =1
b − a. (44)
Find that f (x1|r = 0) = fx(x1).
Basic Numerical Techniques
Outline
Introduction
Numerical Integration
Random Number Generation
Monte Carlo Methods
Conclusion
Basic Numerical Techniques
Monte-Carlo Analysis
I Analysis of complex devices and systems
I Non-linear, non-invertible input/output relationship
I Deriving distributions of outputs: difficult or impossible
Basic idea of Monte Carlo
I Generate inputs (i.e. parameters) randomly
I Solve forward problem many times (M realizations)
I Compute empirical distributions of outputs
Uses of Monte Carlo
I Finding device yield
I Evaluating algorithmic sensitivity
I Deriving solution confidence
I Validating analytical solutions
Basic Numerical Techniques
Monte-Carlo Analysis
I Analysis of complex devices and systems
I Non-linear, non-invertible input/output relationship
I Deriving distributions of outputs: difficult or impossible
Basic idea of Monte Carlo
I Generate inputs (i.e. parameters) randomly
I Solve forward problem many times (M realizations)
I Compute empirical distributions of outputs
Uses of Monte Carlo
I Finding device yield
I Evaluating algorithmic sensitivity
I Deriving solution confidence
I Validating analytical solutions
Basic Numerical Techniques
Monte-Carlo Analysis
I Analysis of complex devices and systems
I Non-linear, non-invertible input/output relationship
I Deriving distributions of outputs: difficult or impossible
Basic idea of Monte Carlo
I Generate inputs (i.e. parameters) randomly
I Solve forward problem many times (M realizations)
I Compute empirical distributions of outputs
Uses of Monte Carlo
I Finding device yield
I Evaluating algorithmic sensitivity
I Deriving solution confidence
I Validating analytical solutions
Basic Numerical Techniques
Monte-Carlo Analysis: Example
Quarter-Wave Transformer Design
ZS
Zin
ℓ
Z1
ZL
Zin = Z1ZL + jZ1 tanβ`
Z1 + jZL tanβ`. (45)
Ideal Parameters
I Impedance:Z1 =
√ZSZL = 70.71Ω
I Length: β` = π/2
Actual Parameters: Manufacturing tolerance
Z1 ∼ N (µZ , σ2Z )
β` ∼ N (µβ`, σ2β`).
µZ = 70.71
µβ` = 90
σ = Tµ
Analyze M = 105 Monte-Carlo realizations, T=10% or 20%.
Basic Numerical Techniques
Monte-Carlo Analysis: Example resultCDF of 105 realizations
0 20 40 60 80 1000
0.2
0.4
0.6
0.8
1
X = |Zin
|
Pr(
X <
abscis
sa)
10%20%
Observations
I If require 40Ω < |Zin| < 60Ω
I T=20%: yield is around 40%
I T=10%: yield is around 70%
Basic Numerical Techniques
Outline
Introduction
Numerical Integration
Random Number Generation
Monte Carlo Methods
Conclusion
Basic Numerical Techniques
Conclusion
Techniques Learned
I Numerically integrating arbitrary functions
I Generating non-uniform RVs
I Analysis with Monte Carlo
Next Time
I Begin with actual CEM methods
I Finite-difference (FD) techniques
Basic Numerical Techniques