forked from SvenCelin/OCS-Assignments-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest2.py
More file actions
45 lines (35 loc) · 1.03 KB
/
Test2.py
File metadata and controls
45 lines (35 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import numpy as np
from numpy import log as ln
import matplotlib.pyplot as plt
import scipy as sp
from mpl_toolkits.mplot3d import axes3d, Axes3D #<-- Note the capitalization!
#Compute the gradient and the Hessian for all functions and determine the set of stationary points
#and characterize every stationary point whether it is a saddle point, (strict) local/global minimum or maximum
#1
def f(x, y):
return (2*x**3. - 6*y**2. + 3*y*x**2.)
#2
def f2(x,y):
return ((x-2*y)**4. + 64*x*y)
#3
def f3(x,y):
return (2*x**2. + 3*y**2. - 2*x*y + 2*x - 3*y)
#4
def f4(x,y):
return (ln(1 + 0.5*(x**2. + 3*y**2.)))
x = np.linspace(-1, 1, 100)
y = np.linspace(-1, 1, 100)
X, Y = np.meshgrid(x, y)
Z = f(X, Y)
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.contour3D(X, Y, Z, 50, cmap='binary')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
ax.set_title('3D contour')
#plt.show() ***REMOVE COMMENT***
#gradient of f1
gradF = np.gradient(f(x,y))
print (f(x,y))
print (gradF)