diff --git a/Homework1/3D_representration.pdf b/Homework1/3D_representration.pdf deleted file mode 100644 index 0845f3a..0000000 Binary files a/Homework1/3D_representration.pdf and /dev/null differ diff --git a/Homework1/post_processing.py b/Homework1/post_processing.py index 0675a56..bfc3f2b 100644 --- a/Homework1/post_processing.py +++ b/Homework1/post_processing.py @@ -1,68 +1,68 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Oct 14 15:19:11 2019 Authors: Omid Ashtari and Armand Sieber Description: Scripts intended to display minimization proplems results """ import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D def objective(X, *args): #objective function to be minimized A = args[0] B = args[1].T S = np.dot(X.T, np.dot(A, X)) - np.dot(X.T, B) return S def plot_results(X_int, A, B, method): # Pre-processing the data to be dispalyed ########################################## # Set domain size and coordinates according to intermediate solution of minimization problem x1 = np.max(np.abs(X_int[:, 0])) x2 = np.max(np.abs(X_int[:, 1])) X_domain = np.linspace(-1.5*x1, 1.5*x1, 100) Y_domain = np.linspace(-1.5*x2, 1.5*x2, 100) xx, yy = np.meshgrid(X_domain, Y_domain) # Compute S for the computational domain (S_post) and intermediate minimization solution (S_int) S_post = np.array([objective(np.array([x , y]), A, B) for x, y in zip(np.ravel(xx), np.ravel(yy))]) # Value of S for 3D plot (whole X-Y domain) S_post = S_post.reshape(xx.shape) S_int = np.array([objective(np.array([x , y]), A, B) for x, y in zip(X_int[:,0], X_int[:,1])]) # Value of S at intermediate minimization steps # Dispalying the results ######################## fig = plt.figure(1) # 3D plot ax = plt.axes(projection = '3d') ax.plot3D(X_int[:,0], X_int[:,1], S_int, 'r--o', alpha = 1.0, zorder = 10) surface = ax.plot_surface(xx, yy, S_post, cmap = 'Greys', edgecolor = 'none', alpha = 1.0, zorder = 0) # zorder 'best' solution found to plot S_int over S_post # --> alternative using mayavi ax.set_xlabel('$x$', fontsize = 14) ax.set_ylabel('$y$', fontsize = 14) ax.set_zlabel('$S$', fontsize = 14) ax.view_init(elev = 60.0, azim = 130.0) ax.set_title('Minimization method: %s' % method, fontsize = 14, pad = 32) - plt.savefig('3D_representration.pdf', bbox_inches = 'tight') + plt.savefig('3D_representation.pdf', bbox_inches = 'tight') fig = plt.figure(2) # 2D contour plot ax = fig.add_subplot(111) ax.contour(xx, yy, S_post, colors = 'k', levels = 20) contour = ax.contourf(xx, yy, S_post, cmap = 'Greys', levels = 20) ax.plot(X_int[:,0], X_int[:,1], 'r--o') ax.set_xlabel('$x$', fontsize = 14) ax.set_ylabel('$y$', fontsize = 14) ax.set_title('Minimization method: %s' % method, fontsize = 14) fig.colorbar(contour, ax=ax) plt.savefig('2D_projection.pdf', bbox_inches = 'tight') plt.show() return 0