Semiconductor
Engineering: Numerical Analysis & Computer Simulations
Lecture
1: Fundamentals of Computer Simulation & Error Analysis
1. Course Introduction &
Logistics
- Instructor: [Professor’s Name]
- Topics: Numerical analysis, computer simulations
(Ch 1-7 by me)
- Today’s Focus: Fundamentals of computer simulation,
sources of computational errors
- Recommended Texts:
- “Numerical Analysis”, “Numerical Simulation”
- “Numerical Recipes” for algorithms & programming
- Programming Tools:
- Text Editor: Microsoft Visual Studio Code
recommended
- Generative AI Usage: Permitted for assignments,
BUT must include your own thoughts and improvements. No
unedited AI output.
- Grading: Term-end assignment (no final exam)
- Support: Class recordings available, email/Slack
for questions
2. Today’s Assignment
(Due: Midnight, June 11th)
Problem 1: Number Base Conversion (Manual Calculation
Required) 1. Convert
to Base 10. 2. Convert
to Base 16. * Please solve manually first; programs can be used for
verification.
Problem 2: Python Program Analysis 1. Choose one
Python program from lecture materials. 2. Explain what each block/part
of the source code does. 3. If unclear, list the parts you don’t
understand and explain why. * Objective: Engage with code,
even if not fully understood.
3. Fundamentals of
Computer Representation
- Binary Nature: Computers operate using binary (base
2) states (0 or 1).
- CPU & memory are built with binary logic.
- Primitive expression in computers is Base 2.
- Human Convenience: Base 2 is verbose. We often use:
- Base 8 (Octal): Digits 0-7.
- Base 16 (Hexadecimal): Digits 0-9, A-F (A=10,
F=15).
3.1 Number Base
Conversion: Base-r to Base-10
- General Formula: For a number
:
- Example 1: Decimal (Base 10)
- Example 2: Binary (Base 2)
- Example 3: Octal (Base 8)
- Example 4: Hexadecimal (Base 16)
- Max 2-digit hex:
3.2 Number Base
Conversion: Base-10 to Base-r
- Method: Repeated division by
r
and
collecting remainders in reverse order.
- Example: Convert
to Base 8
-
remainder
-
remainder
- Reading remainders upwards:
- Verification:
3.3 Data Storage Units: Bits
& Bytes
- Bit (b): Smallest unit of data (0 or 1).
- Byte (B): Fundamental group of 8 bits.
- Can represent
values (0-255).
- Prefixes (Binary vs. Decimal):
- Kilobyte (KB):
bytes
bytes
- Megabyte (MB):
bytes
bytes
- Gigabyte (GB):
bytes
bytes
- Terabyte (TB):
bytes
bytes
- Note: Capital ‘B’ for Byte, lowercase ‘b’ for bit
(e.g., Mbps = Megabits per second).
4. Numerical
Representation in Computer Programs
4.1 Integer Data Types (Whole
Numbers)
- Signed vs. Unsigned:
- Unsigned: Non-negative only
(
to
).
- Signed: Positive and negative (typically
to
).
- Common Sizes:
- 16-bit:
- Unsigned:
to
- Signed:
to
- 32-bit:
- Unsigned:
to
- Signed:
to
- 64-bit: (Standard on modern CPUs)
- Unsigned:
to
- Signed:
to
- Beyond: For extremely large integers (e.g.,
to 50 trillion digits), “multi-precision arithmetic” is needed (software
implementation).
4.2 Floating-Point Data
Types (Real Numbers)
- Purpose: Represent numbers with fractional parts
(real numbers).
- Standard: IEEE 754 standard for
consistent representation.
- Types:
- Binary32 (Single Precision): 32 bits
- Binary64 (Double Precision): 64 bits (common
default)
- Binary128 (Quad Precision): 128 bits
- Structure:
- Sign bit: 1 bit
()
- Exponent: Represents power of 2
- Mantissa (Fraction): Represents fractional
part
4.2 Floating-Point Data Types
(Cont.)
- Binary64 (Double Precision):
- 1 bit sign
- 11 bits exponent
- 52 bits mantissa (fraction)
- Precision:
decimal digits.
- Range:
to
.
- Precision in Semiconductor Physics:
- Energy scales: meV to MeV (e.g.,
at 300K, core electron energies can be keV).
- Requires high precision (typically 64-bit minimum, 128-bit preferred
for some calculations).
- Quad precision (128-bit) often software-implemented, thus
slower.
5. Sources of
Numerical Errors in Computation
- Computers use finite precision: Real numbers
(infinite digits) must be approximated.
- Machine Epsilon: Smallest number such that
.
Fundamental limit of floating-point precision.
5.1 Round-off Error
- Definition: Errors from inexact representation of
real numbers in finite binary digits.
- Example:
cannot be exactly represented in binary.
-
(repeating)
- Accumulation: Repeated operations (e.g., summing
100 times) cause errors to accumulate.
- Loss of Significance (Cancellation Error):
- Subtracting nearly equal large numbers (e.g.,
where
).
- Adding very different magnitude numbers (e.g.,
in 4-digit precision
,
losing
).
- Mitigation: Reformulate equations, use specialized
summation algorithms (e.g., Kahan summation).
5.2 Overflow and Underflow
- Overflow: Result is too large for the data type.
- Ex: Product of two large
double
s exceeds
.
- Underflow: Result is too small (too close to zero)
to be represented accurately, often rounded to zero.
- Ex: A
double
cannot represent numbers smaller than
.
- Physical Example (Boltzmann Factor
):
-
(Silicon),
(specific context):
(No issue).
-
(Oxide),
:
(No issue).
- ,
():
.
- Problem: This value is much smaller than
(min
double
value), leading to underflow to
zero.
- Solution: Requires arbitrary-precision arithmetic
libraries.
5.3 Truncation Error
- Definition: Error from approximating an infinite
mathematical process with a finite one.
- Example: Using a finite number of terms in a Taylor
series expansion:
-
is the truncation error.
5.4 Convergence Error
- Definition: Error when an iterative numerical
method is stopped before reaching the exact solution.
- Example: Terminating a self-consistent field (SCF)
calculation before full convergence.
5.5 Model/Approximation Error
- Definition: Errors due to simplifications in the
underlying physical or mathematical model itself.
- Example: Using a classical model when quantum
effects are significant, neglecting certain interactions.
6. Practical
Implications & Avoiding Errors
6.1 Floating-Point
Comparisons (if (x == y)
)
- Problem: Direct equality comparison of floats is
unreliable due to round-off error.
if (3.0 * 10.0 == 30.0)
might be
False
!
- Solution: Compare absolute difference with a small
tolerance (epsilon).
EPSILON
(e.g.,
or
)
accounts for small inaccuracies.
6.2 Converting
Floating-Point to Integer
- Problem:
int(9.999999999999999)
might
yield 9
instead of 10
.
- Solution: Add a small epsilon before conversion.
- This “nudges” values slightly below an integer threshold up.
- Problem: Subtracting large, nearly equal numbers
leads to significant digit loss.
- Example: Calculating
for large positive
using its Taylor series:
- For
,
intermediate terms are very large, leading to significant cancellation
and an incorrect result (e.g.,
instead of
).
- Solution: Reformulate the expression to avoid
cancellation.
- Instead, calculate
:
- All terms are positive, preventing cancellation. Then, take the
reciprocal.
7. Conclusion & Assignment
Review
- Key Takeaways:
- Computers use binary; other bases are for human convenience.
- Data types (int, float) have finite precision and range.
- Numerical errors (round-off, overflow, underflow, truncation,
cancellation) are inherent.
- Crucial: Understand and mitigate these errors for
reliable simulations.
- Assignment Reminder:
- Problem 1: Base conversion (manual).
- Problem 2: Python code analysis.
- Submit via LMS by midnight, June 11th.
Questions? Thank you. —