#Exercise 10.1
import numpy as np
m = 20
n = 10
A = np.random.randn(m,n)
b = np.random.randn(m)
x = np.linalg.lstsq(A,b)
print(x)
#Exercise 10.2
import numpy as np
from scipy import optimize as op
#x = np.linspace(0,2,1000)
def f(x):
return np.multiply(np.power(np.sin(x-2),2),np.exp(-np.power(x,2)))*(-1)
res = op.minimize_scalar(f)
print(-1*res.fun)
import numpy as np
m = 20
n = 10
A = np.random.randn(m,n)
b = np.random.randn(m)
x = np.linalg.lstsq(A,b)
print(x)
#Exercise 10.2
import numpy as np
from scipy import optimize as op
#x = np.linspace(0,2,1000)
def f(x):
return np.multiply(np.power(np.sin(x-2),2),np.exp(-np.power(x,2)))*(-1)
res = op.minimize_scalar(f)
print(-1*res.fun)