Closed excitedstate closed 1 year ago
Hello! Thank you for your support and contribution to the project.
First of all, I am glad to see that you have completed convex optimization homework 3, problem 4. I will carefully review and compare the solution you provided. If your answer is correct, I will add it to the repository so that others can reference it as well.
As for the source code, it would be great if you could provide it. You can share the code as a GitHub Gist, a link to a code file in your fork of the repository, or directly paste the code snippet in your response. This will help us better understand your solution and make it easier for others to reference and learn from it.
Thank you again for your contribution! Please feel free to contact me if you have any other questions or suggestions.
i'm sorry for i made a mistake, the optimal answer is -7.125. you can see the last iterative point is closer to the contour line -7!
and the following is the code used to plot the contour, feasible region and iterative path.
import matplotlib.pyplot as plt
import numpy as np
def function(x):
return 2 * x[0] ** 2 + 2 * x[1] ** 2 - 2 * x[0] * x[1] - 4 * x[0] - 6 * x[1]
fig = plt.figure()
ax = fig.add_subplot(111)
# # x_range, y_range and internal for contour
x_range = [0, 3]
y_range = [0, 3]
internal = 0.125
# # prepare data points [x, y; z]
ori_x = np.arange(*x_range, internal)
ori_y = np.arange(*y_range, internal)
x, y = np.meshgrid(ori_x, ori_y)
z = function(np.array([x, y]))
# # drawcontour
ax.contour(x, y, z, 10, cmap='RdGy')
ax.clabel(ax.contour(x, y, z, 20), inline=True, fontsize=7)
# # ......................................................
# # iterative points and minimal point when no constraints
iter_points = [[0, 0], [5 / 6, 5 / 6], [1.25, 0.75]]
assert_minimal_point = [7 / 3, 8 / 3]
# # plot iterative points and minimal point
ax.plot([p[0] for p in iter_points], [p[1] for p in iter_points], 'ro-', linewidth=2, markersize=3)
ax.plot(assert_minimal_point[0], assert_minimal_point[1], 'r*-', linewidth=0.5, markersize=5)
# # ......................................................
# # draw feasible region
fr_points = [[0, 0], [0, 1], [1.25, 0.75], [2, 0]]
ax.fill(*zip(*fr_points), color=(.2, 0.1, .2), alpha=0.5)
ax.plot(*zip(*fr_points), color=(.2, 0.1, .2), alpha=0.5)
plt.title("function")
plt.show()
i calculated this question and no code had been wrote for it. if you want to verify the result, please follow the Chapter 7 P55(slides).
Tip: do not use simplex method when you solve LP, just draw the graph.
thank you for your sharing again. wish you a good holiday.
first of all, thanks for sharing your answers, but i noticed that you did not give the final answer of convex optimization homework3 t4, so i share mine.
the first image gives a path of iterative points. they are marked manually. the second image gives the details and we got the optimal answer -4.75 while $x_k=(1.25, 0.75)$