-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtestprj.py
More file actions
24 lines (21 loc) · 729 Bytes
/
Copy pathtestprj.py
File metadata and controls
24 lines (21 loc) · 729 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
A = np.matrix([[3.0, 2.0], [2.0, 6.0]])
b = np.matrix([[2.0], [-8.0]]) # we will use the convention that a vector is a column vector
c = 0.0
def f(x, A, b, c):
return np.sum(0.5 * x.T * A * x - b.T * x + c)
fig = plt.figure(figsize=(10,8))
ax = fig.add_subplot(1,1,1,projection='3d')
size = 20
x1 = list(np.linspace(-6, 6, size))
x2 = list(np.linspace(-6, 6, size))
x1, x2 = np.meshgrid(x1, x2)
zs = np.zeros((size, size))
for i in range(size):
for j in range(size):
x = np.matrix([[x1[i,j]], [x2[i,j]]])
zs[i,j] = f(x, A, b, c)
ax.plot_surface(x1, x2, zs, rstride=1, cstride=1, cmap=cm.coolwarm, linewidth=0)
plt.show()