Homework
Numerical Methods
David Mayerich
Scalable Tissue Imaging and Modeling (STIM) Laboratory
Department of Electrical and Computer Engineering
Cullen College of Engineering
University of Houston
David Mayerich
STIM Laboratory, University of Houston

Homework 1
Real and Complex Sets
Hilbert Spaces
Linear Algebra
Taylor Series
David Mayerich
STIM Laboratory, University of Houston
Calculate \(y=z^2z^*\) where \(z = (2+3i)\)
David Mayerich
STIM Laboratory, University of Houston
Sets and Hilbert Spaces
-
Describe the Hilbert space of \(\mathbf{y} = \mathbf{ABx}\) if \(\mathbf{A}\in \mathbb{R}^{5\times 4}\) and \(\mathbf{x}\in\mathbb{C}^{7}\)
David Mayerich
STIM Laboratory, University of Houston
Calculate \(\langle \mathbf{x}, \mathbf{y} \rangle\)
David Mayerich
STIM Laboratory, University of Houston
Gaussian Elimination
-
Solve the following linear system:
David Mayerich
STIM Laboratory, University of Houston
Taylor Series
-
Calculate a 4th-order Maclaurin series to approximate \(f(x) = e^x \cos{x^2}\)
David Mayerich
STIM Laboratory, University of Houston
Homework 2
Data Types
Promotions
Heap Allocation
David Mayerich
STIM Laboratory, University of Houston
Promotions
-
What are the register contents after the following allocations?
David Mayerich
STIM Laboratory, University of Houston
//...
unsigned char a = 200;
unsigned char b = 2;
unsigned int c = 128;
unsigned int w = c % 7
unsigned int x = a + c;
unsigned int y = (unsigned char)(a + c);
unsigned int z = a * b;
//...w = 2x = 328y = 328 % 256 = 72z = 400 // why not 144?Heap Allocation
-
Allocate space for the following arrays in the GEMM operation:
David Mayerich
STIM Laboratory, University of Houston
given the function signature:
void sgemm(int m, int n, int k, float alpha, float* A, float* B, float beta, float* C)float* A = (float*) malloc(m * k * sizeof(float));
float* B = (float*) malloc(k * n * sizeof(float));
float* C = (float*) malloc(m * n * sizeof(float));Homework 3
Maclaurin Series
Error Terms
Approximating Complex Functions
David Mayerich
STIM Laboratory, University of Houston
Complexity Analysis
-
Calculate the computational complexity of the following algorithms:
David Mayerich
STIM Laboratory, University of Houston
Synthetic Division
-
Use Horner's algorithm to calculate \(p(x)\) and \(p'(x)\)
David Mayerich
STIM Laboratory, University of Houston
Homework 4
Series Expansions
Truncation Error
Relative Error
David Mayerich
STIM Laboratory, University of Houston
Truncation Error in Series
-
Calculate the relative error in the first 3 terms of the following expansion for \(\pi\)
David Mayerich
STIM Laboratory, University of Houston
Radiocarbon Dating
-
You are developing a new radiocarbon dating method. Your test sample is an Egyptian papyrus document that has been officially dated at \(2560\) BCE. Your method estimates the date as \(2830\) BCE. What is the relative error of your method (in percent), assuming that the official date is correct?
David Mayerich
STIM Laboratory, University of Houston
Relative error requires a ratio scale.
The time scale in this case is relative to the date that the papyrus was created.
The dating method is measuring how much time has passed since the manuscript was created.
Homework 5
Signed and Unsigned Integers
Memory Addressing
Overflow
Floating Point
David Mayerich
STIM Laboratory, University of Houston
Signed Integers
-
What is the smallest value that can be represented with a 5-bit signed integer using two's complement?
-
Convert from positive to negative:
-
perform a NOT operation on the positive number
-
add 1
-
-
Reverse that to convert to positive:
David Mayerich
STIM Laboratory, University of Houston
Nintendo Memory
-
A Nintendo Entertainment System (NES) used a pixel processing unit (PPU) with 246 bytes of addressable sprite memory that could be used to process motion on the screen. How many bits were required to address this memory space?
David Mayerich
STIM Laboratory, University of Houston
\(3\) bits can address \(2^3 = 8\) locations
\(7\) bits can address \(2^7 = 128\) locations
\(8\) bits can address \(2^8 = 256\) locations
This is why machines like the NES are often called \(8\)-bit systems
NeoGeo Memory
-
The NeoGeo had \(64\) kilobytes (kB) of main VRAM. How many bits were required to address this memory space?
David Mayerich
STIM Laboratory, University of Houston
\(15\) bits can address \(2^{15}=32768\) locations
\(16\) bits can address \(2^{16}=65536\) locations
-
The SI standard defines a kilobyte (kB) as \(1000\) bytes
-
The JEDEC standard defined a kilobyte as \(2^{10} = 1024\) bytes
-
Since the power-of-two standard is still used in semiconductor manufacture, it is now generally referred to as a kibibyte (KiB)
Donkey Kong
-
The number of seconds given to complete each level \(L\) in the video game Donkey Kong is \(s=\text{min}(10L+40, 80)\). Why has nobody gotten past level 22?
David Mayerich
STIM Laboratory, University of Houston
Level 22 would allow the player \(s=\text{min}(260, 80) = 80\), right?
What if the calculation used \(8\)-bit integers?
Floating Point
-
Convert the following \(8\)-bit floating point values to decimal assuming the following format with a bias of \(7\):
David Mayerich
STIM Laboratory, University of Houston
sign
exponent
mantissa
Homework 8
Solving Linear Systems
Loss of Precision
Partial Pivoting
David Mayerich
STIM Laboratory, University of Houston
Loss of Precision
-
Solve the following linear system using (1) Gaussian Elimination and (2) Partial Pivoting with 3 digits of precision. Provide the error for each.
David Mayerich
STIM Laboratory, University of Houston
Gaussian Elimination
Partial Pivoting
Partial Pivoting
-
Solve the following linear system using partial pivoting and provide the index vector
David Mayerich
STIM Laboratory, University of Houston
Homework 9
LUP Decomposition
Matrix Inversion
Condition Numbers
David Mayerich
STIM Laboratory, University of Houston
LUP Decomposition
-
Calculate the LUP decomposition of the following matrix:
David Mayerich
STIM Laboratory, University of Houston
Matrix Inversion
-
Calculate the middle column of \(\mathbf{A}^{-1}\)
David Mayerich
STIM Laboratory, University of Houston
Homework 10
Finite Difference Methods
Integration
David Mayerich
STIM Laboratory, University of Houston
Finite Differences
-
Compare the relative error using the central difference method to approximate:
David Mayerich
STIM Laboratory, University of Houston
at \(x=2\) using a spacing \(x_\Delta = 1\), \(0.1\), \(0.01\)
Integration
-
Compare the relative errors for the integral using two iterations of the trapezoid rule and one iteration of Simpson's rule. Keep 3 significant digits from the function evaluations:
David Mayerich
STIM Laboratory, University of Houston
Homework 11
Differential Equations
Euler's Method
David Mayerich
STIM Laboratory, University of Houston
Euler's Method
-
Approximate the solution to the differential equation using 6 iterations of Euler's method with a spacing of \(\Delta_x=0.5\) and an initial value of \(y(0)=1\):
David Mayerich
STIM Laboratory, University of Houston
| xn | yn | dy/dx | yn+1 | y(xn+1) | Er | |
|---|---|---|---|---|---|---|
| 1 | 0 | 1 | 0 | 1 | 1.22 | 18% |
| 2 | 0.5 | 1 | 0.722 | 1.36 | 1.38 | 1.4% |
| 3 | 1.0 | 1.36 | -0.602 | 1.06 | 0.150 | 606% |
| 4 | 1.5 | 1.06 | -4.22 | -1.05 | -1.41 | 26% |
| 5 | 2.0 | -1.05 | 0.413 | -0.844 | 0.966 | 187% |
| 6 | 2.5 | -0.844 | 5.16 | 1.74 | -0.499 | 448% |

Homework 12
Random Numbers
Linear Congruential Generators
Mersenne Twister
David Mayerich
STIM Laboratory, University of Houston
Multiplicative LCGs
-
Determine the period of a \(5\)-bit MLCG with a modulus of \(31\) and a multiplier of \(4\) by selecting a seed and evaluating:
David Mayerich
STIM Laboratory, University of Houston
Linear Congruential Generators
-
Select the missing parameters to maximize the period for the following LCGs by meeting the Hull-Dobel criterion, where \(m\) is the modulus, \(a\) is the multiplier, and \(c\) is the increment:
David Mayerich
STIM Laboratory, University of Houston
(prime numbers between \(1\) and \(24\))
(assuming a \(5\)-bit register)
(8 doesn't have any prime factors but is divisible by \(4\))
C++ Random Number Generators
-
Write the code to generate random numbers in the range of \([0, 2\pi)\) using the Mersenne Twister algorithm. Seed it with the number of seconds since January 1, 1970
David Mayerich
STIM Laboratory, University of Houston
#include <random>
#include <time>
\\......
std::uniform_double_distribution<double> dist(0, 2 * M_PI);
std::mt19937 mt(time(NULL));
double x = dist(mt());ECE 3340 Homework
By STIM Laboratory
ECE 3340 Homework
- 165