[SciPy-user] Handling of constraints in cobyla

Nils Wagner nwagner at mecha.uni-stuttgart.de
Fri Jun 17 11:03:44 EDT 2005


Hi all,

How can I replace the first two constraints (con1 and con2) in my 
program (see below) ?
In general the constraints con1 and con2 are not given explicitely in my 
problem, but they follow from an eigenvalue analysis.

w = linalg.eigvals(K,M)
w[0].real - xi0
w[1].real - xi0

If I have more constraints like con3 and con4 is there a way to simplify 
the procedure ?

I would be grateful for your help

Thanks in advance

                                       Nils

from scipy import *

def test2(x,xi0):
        function = lambda x: dot(c,x)
        con1 = lambda x: (4*x[0]+2*x[1])/3-xi0   # First Eigenvalue is 
no lower than xi0
        con2 = lambda x: 4*x[0]-xi0              # Second eigenvalue is 
no lower than xi0
        con3 = lambda x: x[0]                    # Stiffness parameter >= 0
        con4 = lambda x: x[1]                    # Stiffness parameter >= 0

        x = optimize.fmin_cobyla(function, x0, [con1, con2, con3, con4], 
rhobeg=0.1,
                           rhoend=1e-5, iprint=0, maxfun=1400)
        return x

c = array(([3,1]))
#
# Initial stiffness parameters
#
x0 = array(([1.3,1]))
#
# Parameter-dependent stiffness matrix
#
K = array(([4*x0[0]+x0[1],x0[1]],[x0[1],4*x0[0]+x0[1]]))
#
# Constant mass matrix
#
M = array(([2,1],[1,2]))

w = linalg.eigvals(K,M)

print 'Eigenvalues of the initial design',w
print 'Exakt eigenvalues',(4*x0[0]+2*x0[1])/3, 4*x0[0]
#
# Find the smallest eigenvalue
#
ind = argsort(w.real)
ws = take(w,ind)
xi0 = ws[0].real

x = test2(x0,xi0)

print 'Optimal stiffness parameters',x

M = array(([2,1],[1,2]))
K = array(([4*x[0]+x[1],x[1]],[x[1],4*x[0]+x[1]]))

w = linalg.eigvals(K,M)
print 'Eigenvalues of the optimal design',w





More information about the SciPy-User mailing list