Code for HW 2



```python
import numpy as np 
```

Q4



```python
v0 = np.array([0.5, 0.5, 0.5, 0.5]).T
v1 = np.array([0.5, 0.5, -0.5, -0.5]).T
v2 = np.array([0.5, -0.5, 0.5, -0.5]).T
```


```python
A = 0.5*np.matrix([[1, 1, 1, 1],[1, 1, -1 ,-1],[1, -1, 1, -1]])
```


```python
y = np.matrix([-0.5, 0.5, 0.5, 1.5]).T
```


```python
from sympy import *
```


```python
a, b, c, d = symbols('a b c d')
v3 = np.array([a, b, c, d])
answer = solve([v0.dot(v3), v1.dot(v3), v2.dot(v3), v3.dot(v3)-1], (a, b, c, d))
```


```python
q1 = np.asarray(answer[0], dtype='float')
q2 = np.asarray(answer[1], dtype='float')

print(q1)
print('------------')
print(q2)
```

    [-0.5  0.5  0.5 -0.5]
    ------------
    [ 0.5 -0.5 -0.5  0.5]



```python
A1 = np.stack((v0, v1, v2,q1),axis = -1)

print(A1)
```

    [[ 0.5  0.5  0.5 -0.5]
     [ 0.5  0.5 -0.5  0.5]
     [ 0.5 -0.5  0.5  0.5]
     [ 0.5 -0.5 -0.5 -0.5]]



```python
A2 = np.stack((v0, v1, v2, q2),axis = -1)

print(A2)
```

    [[ 0.5  0.5  0.5  0.5]
     [ 0.5  0.5 -0.5 -0.5]
     [ 0.5 -0.5  0.5 -0.5]
     [ 0.5 -0.5 -0.5  0.5]]


y = Ac

c = inv(C)*y


```python
from numpy import linalg as la
```


```python
print("Shape of A matrix: ",A1.shape)

print("Shape of y: ", y.shape)
```

    Shape of A matrix:  (4, 4)
    Shape of y:  (4, 1)


Evaluating the coefficients needed to produce y give the bases matrix A1 and A2


```python
A1_prime = la.inv(A1)
print(np.dot(A1_prime,y))
```

    [[ 1.]
     [-1.]
     [-1.]
     [ 0.]]



```python
A2_prime = la.inv(A2)
print(np.dot(A2_prime,y))
```

    [[ 1.]
     [-1.]
     [-1.]
     [ 0.]]


## Q4


```python
y = np.reshape(y, (4,1))
```


```python
q1 = np.reshape(q1, (4,1))
q2 = np.reshape(q2, (4,1))
```


```python
v0 = np.reshape(v0, (4,1))
v1 = np.reshape(v1, (4,1))
v2 = np.reshape(v2, (4,1))
```


```python
Q1 = np.hstack((y,v1,v2,q1))
print(la.matrix_rank(Q1))
```

    4



```python
Q2 = np.hstack((y,v0,v2,q1))
print(la.matrix_rank(Q2))
```

    4



```python
Q3 = np.hstack((y,v0,v1,v2))
print(la.matrix_rank(Q3))
```

    3



```python
Q4 = np.hstack((y,v1,v2,q1-2*v1))
print(la.matrix_rank(Q4))
```

    4


Select option 1,2 and 4


```python

```

f999c0314a91230a9b6432dead96a5f13dbf8751
ipynb
Jupyter Notebook
HaarBasis/HW 2.ipynb
AkshayPR244/Coursera-EPFL-Digital-Signal-Processing
bdf9c65e2c02f0a99336cbe60ebac919891e05e3
MIT
2020-07-24T03:16:36.000Z
2020-09-25T10:21:00.000Z
HaarBasis/HW 2.ipynb
AkshayPR244/Coursera-EPFL-Digital-Signal-Processing
bdf9c65e2c02f0a99336cbe60ebac919891e05e3
MIT
HaarBasis/HW 2.ipynb
AkshayPR244/Coursera-EPFL-Digital-Signal-Processing
bdf9c65e2c02f0a99336cbe60ebac919891e05e3
MIT
2021-03-23T19:37:53.000Z
2021-03-23T19:37:53.000Z
Qwen/Qwen-72B
1. YES
2. YES