问题描述
A = np.array([[7.958e+01 1.440e+00 6.971e+01 1.040e+00 3.733e+01 1.570e+01],[5.800e+00 3.200e-01 7.200e-01 1.020e+00 1.109e+01 4.980e+00],[1.460e+00 3.400e-01 6.600e-01 6.466e+01 4.050e+00 2.560e+00],[4.340e+00 5.256e+01 1.252e+01 1.427e+01 1.865e+01 4.231e+01],[9.200e-01 2.070e+00 3.610e+00 3.540e+00 5.100e+00 2.380e+00],[0.000e+00 6.000e-01 9.000e-02 2.100e-01 5.700e-01 1.280e+00],[1.450e+00 9.600e-02 2.800e-01 1.500e-01 1.478e+00 4.620e-01],[4.860e-01 2.700e-02 0.000e+00 3.000e-01 7.880e-01 2.330e-01]])
b = np.array([24.6875,6.577,2.2169,59.9135,3.3156,1.0645,0.7319,0.3567])
# Define and solve the CVXPY problem.
x = cp.Variable(6)
objective = cp.Minimize(cp.sum_squares(A@x - b))
constraints = [0 <= x,x <= 1,sum(x) == 1]
prob = cp.Problem(objective,constraints)
prob.solve()
#Print result.
print("\nThe optimal value is",prob.value)
print("The optimal x is")
print(x.value)
print("The norm of the residual is ",cp.norm(A @ x - b,p=2).value)
summ = sum(x.value)
print(summ)
>>>>
The optimal value is 370.4259696888074
The optimal x is
[-3.55262420e-18 7.02949975e-01 1.81476423e-01 -6.08113127e-16
-3.36614249e-16 1.15573602e-01]
The norm of the residual is 19.24645343144574
1.000000000000002
(此方案表示输入材料的样品组成百分比。输入材料(标记为材料 1 到 4)具有以元素 A 到 J 测量的化学成分。样品组成也以元素 A 到 J 测量。{ {3}})
我尝试了许多不同的求和方法,例如cp.sum_entries(x) 和np.sum(x)。我也不知道为什么我返回的 x 值不在 0 和 1 之间...
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)