import marimo __generated_with = "0.6.21-dev3" app = marimo.App() @app.cell def __(): import cvxpy as cp import numpy as np import matplotlib.pyplot as plt return cp, np, plt @app.cell def __(np): n = 2 m = 50 # U is a 2 x m matrix. Each column is a single sample u_i from the problem statement. U = np.array( [ [ 1.824183228637652032e00, 1.349093690455489103e00, 6.966316403935147727e-01, 7.599387854623529392e-01, 2.388321695850912363e00, 8.651370608981923116e-01, 1.863922545015865406e00, 7.099743941474848663e-01, 6.005484882320809570e-01, 4.561429569892232472e-01, 5.328296545713475663e-01, 2.138547819234526415e00, 1.906676474276197464e00, 1.015547309536922516e00, 8.765948388006337133e-01, 1.648147347399247842e00, 1.027902202451572045e00, 2.145586297520478691e00, 1.793440421753045744e00, 1.020535583041398908e00, 8.977911075271942654e-01, 1.530480229262339398e00, 2.478088034137528872e-01, 2.617415807793897820e00, 2.081978553098443374e00, 1.891226687205936452e00, 8.222497927065576251e-01, 5.803514604868882376e-01, 1.158670193449639063e00, 6.016685032455900695e-01, 5.605410828151705660e-01, 2.508815467550573164e00, 2.230201413385580977e00, 1.170848897912992514e00, 2.256355929901105561e00, 6.686991510936428629e-01, 2.040269595792217672e00, 3.634166812924328749e-01, 5.418647611079159265e-01, 6.631470058399455692e-01, 4.286142597532469622e-01, 2.155925078996823618e00, 2.379380016960549682e00, 6.343212414048013947e-01, 1.469076407947448981e00, 1.225322035289937439e00, 1.467602887401966871e00, 9.345319187253748883e-01, 1.985592768641736505e00, 2.106896115090134636e00, ], [ -9.644136284187876385e-01, 1.069547315003422927e00, 6.733229334437943470e-01, 7.788072961810316164e-01, -9.467465278344706636e-01, -8.591303443863639311e-01, 1.279527420871080956e00, 5.314829019311283487e-01, 6.975676079749143499e-02, -4.641873429414754559e-01, -2.094571396598311763e-01, -8.003479827938377866e-01, 6.135280782546607137e-01, -9.961307468791747999e-01, -8.765215480412106297e-01, 9.655406812422813179e-01, 1.011230180540185541e00, 6.105416770440197372e-01, 9.486552370654932620e-01, -9.863592657836954825e-01, 7.695327845100754516e-01, -1.060072365810699413e00, -4.041043465424410952e-01, -2.352952920283236105e-01, 7.560391050507236921e-01, -9.454246095204003053e-01, -5.303145312191936966e-01, 5.979590038743245461e-01, -1.154309511133019717e00, -6.123184171955468047e-01, -1.464683782538583889e-01, -1.839128688968104386e-01, 4.250070477845909744e-01, 8.861864983476224200e-01, 3.927648421593328276e-01, -6.726102374256350824e-01, -1.047252884197514833e00, 1.825096825995130845e-01, -4.482373962742914886e-01, 5.115625649313135792e-01, 7.846201103116770548e-02, 6.006325432819290544e-01, -5.710733714464664157e-01, 4.725559971890586075e-01, -8.440290321502940118e-01, -1.003920890712479475e00, -1.067089412136528637e00, 7.909281966910661765e-01, -1.059509163675931065e00, -7.136351632325785843e-01, ], ] ) return U, m, n @app.cell def __(cp): c = cp.Variable(2) t = cp.Variable() return c, t @app.cell def __(cp): # Fill in the `...`! prob = cp.Problem(...) prob.solve() return prob, @app.cell def __(U, c, np, plt, t): r = np.sqrt(t.value + np.linalg.norm(c.value) ** 2) print("The center is", c.value, "and the radius is", r) fig, ax = plt.subplots() ax.scatter(U[0, :], U[1, :], edgecolor="k", color="w") cir = plt.Circle( c.value, r, color="k", fill=False, linestyle="dashed", alpha=0.5 ) ax.set_aspect("equal", adjustable="box") ax.add_patch(cir) plt.savefig("fitted_sphere.eps", dpi=300) plt.show() return ax, cir, fig, r @app.cell def __(): import marimo as mo return mo, if __name__ == "__main__": app.run()