Skip to content

Commit

Permalink
Fix ellipse_approx tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Oct 8, 2024
1 parent 5eba494 commit 16ac20d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions docs/src/tutorials/conic/ellipse_approx.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ plot = Plots.scatter(
model = Model(SCS.Optimizer)
## We need to use a tighter tolerance for this example, otherwise the bounding
## ellipse won't actually be bounding...
set_attribute(model, "eps_rel", 1e-6)
set_attribute(model, "eps_rel", 1e-7)
set_silent(model)
m, n = size(S)
@variable(model, z[1:n])
Expand Down Expand Up @@ -124,11 +124,13 @@ D = value.(Z)

c = D \ value.(z)

# Finally, overlaying the solution in the plot we see the minimal volume approximating
# ellipsoid:
# We can check that each point lies inside the ellipsoid, by checking if the
# largest normalized radius is less than 1:

largest_radius = maximum(map(x -> (x - c)' * D * (x - c), eachrow(S)))

Test.@test isapprox(D, [0.00707 -0.0102; -0.0102173 0.0175624]; atol = 1e-2) #src
Test.@test isapprox(c, [-3.24802, -1.842825]; atol = 1e-2) #src
# Finally, overlaying the solution in the plot we see the minimal volume
# approximating ellipsoid:

P = sqrt(D)
q = -P * c
Expand Down Expand Up @@ -211,7 +213,7 @@ f = [1 - S[i, :]' * Z * S[i, :] + 2 * S[i, :]' * z - s for i in 1:m]
@objective(model, Max, 1 * t + 0)
optimize!(model)
Test.@test is_solved_and_feasible(model)
Test.@test isapprox(D, value.(Z); atol = 1e-6) #src
Test.@test isapprox(D, value.(Z); atol = 1e-3) #src
solve_time_1 = solve_time(model)

# This formulation gives the much smaller graph:
Expand Down

0 comments on commit 16ac20d

Please sign in to comment.