# AMATH 301 - HW1
University of Washington\
Due 10/6/2021


```python
# Import Block
import numpy as np
import sympy as sp
sp.init_printing() # for pretty print with LaTeX/Mathjax
```

## Part 1


```python
# Define absolute error function that takes initial value as input
def abserr(x):
    for j in range(0,x*10):
        x = x - 0.1
    return abs(0 - x)

# Answers
A1 = abserr(1000)
A2 = abserr(10000)
A3 = abserr(100000)

# Debug displays below (comment/uncomment blocks for debug)

# display(A1)
# display(A2)
# display(A3)
```

## Part 2


```python
# Define matrices
A = np.matrix([[1,2],[-1,1]])
B = np.eye(2).astype(int)*2
C = np.matrix([[2,0,-3],[0,0,-1]])
D = np.matrix([[1,2],[2,3],[-1,0]])
x = np.matrix([[1],[0]])
y = np.matrix([[0],[1]])
z = D[:,0]

# Answers
# using numpy.dot() avoids value error from dimensions when multiplying
A4 = A + B
A5 = 3*x - 4*y
A6 = A.dot(x)
A7 = B.dot(x-y)
A8 = D.dot(x)
A9 = D.dot(y) + z
A10 = A.dot(B)
A11 = B.dot(C)
A12 = C.dot(D)

# Debug displays below (comment/uncomment blocks for debug)

# display(sp.Matrix(A4))
# display(sp.Matrix(A5))
# display(sp.Matrix(A6))
# display(sp.Matrix(A7))
# display(sp.Matrix(A8))
# display(sp.Matrix(A9))
# display(sp.Matrix(A10))
display(sp.Matrix(A11))
display(sp.Matrix(A12))
```


$\displaystyle \left[\begin{matrix}4 & 0 & -6\\0 & 0 & -2\end{matrix}\right]$



$\displaystyle \left[\begin{matrix}5 & 4\\1 & 0\end{matrix}\right]$


## Part 3


```python
# Define parameters

p = [0.8,1.5,2.8,3.2,3.5,3.65]
Aarray = np.matrix(np.ones(6)*0.5)

# Loop through arrays
for j in range(2,51):
#     i = np.insert(i,len(i),j,axis=0)
    Aarray = np.insert(Aarray,len(Aarray),np.zeros(len(p)),axis=0)
    for k in range(len(p)):
        xn = Aarray[len(Aarray)-2,k]
        Aarray[len(Aarray)-1,k] = p[k]*xn*(1-xn)

# Full array for debugging (Comment/uncomment below for debug)

# i = np.matrix(range(1,51)).reshape(50,1) # iterations
# labels = sp.Matrix([["x", "A13(x)", "A14(x)", "A15(x)", "A16(x)", "A17(x)", "A18(x)"]])
# Part3 = labels.row_insert(1,sp.Matrix(np.append(i,Aarray,axis=1)))
# display(Part3)
```


```python
# Part 3 Answers
A13 = Aarray[:,0]
A14 = Aarray[:,1]
A15 = Aarray[:,2]
A16 = Aarray[:,3]
A17 = Aarray[:,4]
A18 = Aarray[:,5]

# Debug display (comment/uncomment below for debug)

# display(sp.Matrix(A13))
```

348230e8c6a85b62a0e3457713a3cca850d7201c
ipynb
Jupyter Notebook
scientific_computing_UW-AMATH301/HW_Python/AMATH301_HW1.ipynb
jot33/learn_data_science
8324672acff2523bc7a98eacaec96dd97335af09
MIT
scientific_computing_UW-AMATH301/HW_Python/AMATH301_HW1.ipynb
jot33/learn_data_science
8324672acff2523bc7a98eacaec96dd97335af09
MIT
scientific_computing_UW-AMATH301/HW_Python/AMATH301_HW1.ipynb
jot33/learn_data_science
8324672acff2523bc7a98eacaec96dd97335af09
MIT
Qwen/Qwen-72B
1. YES
2. YES