Beispiel #1
0
idx = find(crit<=0.500)
#rohs = rohs[idx[0]]
rohs = rohs[idx[0]]
A3 = vstack([A,identity(m)*sqrt(rohs)])
b3  = vstack([ones((n,1)),sqrt(rohs)*0.5*ones((m,1))])
p_ls_reg = np.linalg.lstsq(A3, b3)[0]
val_ls_reg = np.max(np.abs(log(A*matrix(p_ls_reg))))
print p_ls_reg
print val_ls_reg


#solution 4 chebyshev approximation
from cvxpy import Minimize, normInf, Variable, Problem, inv_pos

x=Variable (m,1)
objective = Minimize(normInf(matrix(A)*x-ones((n,1))))
constraints =[x>=0,x<=1]
pro = Problem(objective, constraints) 
result = pro.solve()
print x.value
val_ls_chev = np.max(np.abs(log(A*matrix(x.value))))
print val_ls_chev

#solution 5 cvxpy

from cvxpy import max
y=Variable (m,1)
Am = matrix(A)
qq = [max(Am[i,:]*y,inv_pos(Am[i,:]*y)) for i in range(n)]
objective1 = Minimize(max(*qq))
constraints1 =[y>=0,y<=1]
Beispiel #2
0
Atot1 = hstack([Are, -Aim])
Atot2 = hstack([Aim, Are])
Atot = matrix(vstack([Atot1, Atot2]))
btot = matrix(vstack([bre, bim]))
z_2 = Atot.T * inv(Atot * Atot.T) * btot
x2 = z_2[0:99] + 1j * z_2[100:199]
print x2

# cvxpy
from cvxpy import Variable, norm2, Problem, Minimize

x = Variable(2 * n, 1)
objective = Minimize(norm2(x))
constraints = [Atot * x == btot]
pro = Problem(objective, constraints)
result = pro.solve()
xnorm = x.value[0:99] + 1j * x.value[100:199]
print x2 - xnorm
# cvxpy norminf
from cvxpy import normInf, norm1

xinf = Variable(2 * n, 1)
objective1 = Minimize(normInf(xinf))
constraints1 = [Atot * xinf == btot]
pro1 = Problem(objective1, constraints1)
result = pro1.solve()
# print xinf.value[0:99]+1j*xinf.value[100:199]
scatter(x.value[0:99], x.value[100:199])
scatter(xinf.value[0:99], xinf.value[100:199], c="r", marker="D")