我需要把我的代码从matlab cvx翻译成python one,如果有任何帮助我会很高兴。
eps = .1;
A = [-1 +1 0 0 0 0 0 0 -1; +1 0 -1 0 0 0 0 -1 0;x一个一个一个一个x一个一个二个x'从cvx到python cvx的翻译。
deyfvvtc1#
从cvx到python www.example.com的翻译cvx.py是:
import cvxpy as cp eps = .1 A = [[-1, 1, 0, 0, 0, 0, 0, 0, -1], [1, 0, -1, 0, 0, 0, 0, -1, 0], [0, 1, 1, -1, 0, 0, 0, 0, 0], [0, 0, 0, 1, -1, -1, 0, 0, 0], [0, 0, 0, 0, 1, 0, 1, 0, 1], [0, 0, 0, 0, 0, 1, -1, 1, 0]] s = [1, 0, 0, 0, -1, 0] t = [0, 1, 0, 0, 0, -1] x_star = cp.Variable(len(A[0])) y_star = cp.Variable(len(A[0])) mu_star = cp.Variable(len(s)) nu_star = cp.Variable(len(t)) objective = cp.Minimize(cp.sum_squares(x_star + y_star) + eps * (cp.sum_squares(x_star) + cp.sum_squares(y_star))) constraints = [A * x_star + s == 0, A * y_star + t == 0, x_star >= 0, y_star >= 0] prob = cp.Problem(objective, constraints) prob.solve() f_min = prob.value
1条答案
按热度按时间deyfvvtc1#
从cvx到python www.example.com的翻译cvx.py是: