Files
tunmnlu/task_2/others-answer/omsa-main/ISYE-8803-OAN/hw5/l1eq_pd.R
louiscklaw 9035c1312b update,
2025-02-01 02:09:32 +08:00

15 lines
411 B
R

# min |x|_1 subject to Ax = b
# library(CVXR)
l1eq_pd <- function(x0, A, b){
n <- length(x0)
if (is.complex(x0) | is.complex(A) | is.complex(b)){
x <- Variable(n, complex=TRUE)
}else{
x <- Variable(n)
}
objective <- Minimize(CVXR::norm1(x))
constraints <- list(A %*% x == b)
problem <- Problem(objective, constraints)
result <- solve(problem, solver='SCS')
return(result$getValue(x))
}