The default solver in CVXR is Clarabel. However, it is not always the best solver to use. As an example, let us consider again the catenary problem.
We will change the problem slightly to use a finer discretization from 101 points to say 501.
## Problem data
m <- 501
L <- 2
h <- L / (m - 1)
## Form objective
x <- Variable(m)
y <- Variable(m)
objective <- Minimize(sum(y))
## Form constraints
constraints <- list(x[1] == 0, y[1] == 1,
x[m] == 1, y[m] == 1,
diff(x)^2 + diff(y)^2 <= h^2)
## Solve the catenary problem
prob <- Problem(objective, constraints)
result <- psolve(prob, solver = "CLARABEL")
Warning: Solution may be inaccurate. Try another solver, adjusting the solver settings,
or solve with `verbose = TRUE` for more information.
The solution status is no longer optimal.
cat("Solution status is", status(prob))
Solution status is optimal_inaccurate
In such cases, using a different solver may give more accurate results. Let us try MOSEK for example.
result <- psolve(prob, solver = "MOSEK")
cat("Solution status is", status(prob))
Solution status is optimal
This returns an optimal solution.
Different solvers have varying strengths, and it is worth trying alternatives when one solver does not produce satisfactory results.
Session Info
R version 4.5.2 (2025-10-31)
Platform: aarch64-apple-darwin20
Running under: macOS Tahoe 26.3
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.1
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
time zone: America/Los_Angeles
tzcode source: internal
attached base packages:
[1] stats graphics grDevices datasets utils methods base
other attached packages:
[1] CVXR_1.8.0.9213
loaded via a namespace (and not attached):
[1] backports_1.5.0 digest_0.6.39 fastmap_1.2.0 xfun_0.56
[5] Matrix_1.7-4 Rmosek_11.1.1 lattice_0.22-9 osqp_1.0.0
[9] knitr_1.51 gmp_0.7-5.1 htmltools_0.5.9 rmarkdown_2.30
[13] cli_3.6.5 S7_0.2.1 clarabel_0.11.2 grid_4.5.2
[17] scs_3.2.7 compiler_4.5.2 highs_1.12.0-3 tools_4.5.2
[21] checkmate_2.3.4 evaluate_1.0.5 Rcpp_1.1.1 yaml_2.3.12
[25] otel_0.2.0 rlang_1.1.7 jsonlite_2.0.0 htmlwidgets_1.6.4