1

I am trying to illustrate the definition in Example 2.8 in Boyd & Vandenberghe's Convex Optimization.

This is the definition from page 37 of Boyd & Vandenberghe's Convex Optimization


As I suspect, I should reach to something like the graph in Figure 2.13. but my plot looks different. I don't know what's wrong with my understanding.

This is my Python code:

import numpy as np
import matplotlib.pyplot as plt
import math
def MyPlot(x1, x2):
    plt.plot(t, x1 * np.cos( t) + x2 * np.cos(2* t))

t = np.linspace(0, math.pi, 100) # Create a list of evenly-spaced numbers over the range

x1 = np.linspace(-10,10, 4) x2 = np.linspace(-10,10, 4) print ( x1)

for i in x1: for j in x2: MyPlot(i,j)

plt.show()


I got the following plot

The figure I get

but should have gotten the following

This is what I should get

SaraK
  • 21
  • What have you done to confine $x$ to $S$? – Ali Jan 31 '22 at 10:52
  • Scaling the range of x does not change the plot except for a scale. I take a range of (-10 , 10) without loss of generality @Ali – SaraK Feb 01 '22 at 12:34
  • The set $S$ includes only values of $x$ satisfying a particular property. What have you done to ensure that property is satisfied by the values of $x$ for which you are plotting? – Ali Feb 01 '22 at 12:36
  • Nothing. Because I draw it for several $x$s that are not necessarily in $S$. Verifying that is the next step I think. Am I right? @Ali – SaraK Feb 01 '22 at 12:56
  • Well yes. If you exclude values of $x$ that don't satisfy the property then you should get something that looks more like the plot in the book. – Ali Feb 01 '22 at 12:57
  • I am plotting "all" of them... so it should be included.... @Ali – SaraK Feb 01 '22 at 12:59
  • The plot in the book is just for a couple of random values of $x\in S$ and their mean. There are indeed lines among those that you have plotted that would have done the job just as well. But I'm not sure this exercise will teach you anything about convex optimisation. – Ali Feb 01 '22 at 13:04
  • So I can pass through it and let it be unsolved. Because non of the ones I have plotted behave similarly to the one in the book. But It seems there is nothing to worry about. @Ali – SaraK Feb 01 '22 at 13:14

0 Answers0