An example showing that the intersection of (any number of) convex sets is convex.
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
x1s = np.arange(-2, 2, 0.1)
so
$$x_2 = \frac{p(t) - x1 \cos(t)}{\cos(2t)}$$def f_pos(x1, t):
"""when p(t) = 1"""
return (1 - x1 * np.cos(t)) / np.cos(2 * t)
def f_neg(x1, t):
"""when p(t) = -1"""
return (- 1 - x1 * np.cos(t)) / np.cos(2 * t)
t_vals = np.arange(-np.pi / 3, np.pi / 3, 0.05)
for index, t in enumerate(t_vals):
for f, label, color in zip(
[f_pos, f_neg],
["pos", "neg"],
["blue", "red"],
):
x2s = f(x1s, t=t)
plt.plot(
x1s,
x2s,
label=label,
color=color,
)
if index == 0:
plt.legend(loc="upper left", bbox_to_anchor=(1, 1))
plt.grid()
plt.xlabel("x1")
plt.ylabel("x2")
_ = plt.ylim(-2, 2)
for index, t in enumerate(t_vals):
for f, label, color in zip(
[f_pos, f_neg],
["pos", "neg"],
["blue", "red"],
):
x2s = f(x1s, t=t)
plt.plot(
x1s,
x2s,
label=label,
color=color,
)
if index == 0:
plt.legend(loc="upper left", bbox_to_anchor=(1, 1))
plt.grid()
plt.xlabel("x1")
plt.ylabel("x2")
_ = plt.ylim(-5, 5)