Ask Your Question

bennison's profile - activity

2018-01-02 12:02:23 +0100 received badge  Notable Question (source)
2016-03-15 16:33:21 +0100 received badge  Popular Question (source)
2012-04-06 12:29:50 +0100 commented answer error using minimize_constrained

Somebody on irc suggested: "def constraint(u): return u[2] - 1" instead of "[u02-1]" and it worked. That way constraint is a function. Thx for your help.

2012-04-06 12:25:21 +0100 commented question error using minimize_constrained

K and des were not causing any problems (they are stiffness matrix and right hand side of finite elements method) since even with zero matrix and zero vector I would get the same error.

2012-04-06 11:53:10 +0100 received badge  Supporter (source)
2012-04-06 10:56:27 +0100 asked a question error using minimize_constrained

When I use minimize_constrained(), I get the following error:

File "", line 1, in <module>

  File "/tmp/tmp81ftcX/___code___.py", line 72, in <module>
    minimize_constrained(T, [_sage_const_1 ], nil)
  File "/sagenb/sage_install/sage-4.8-sage.math.washington.edu-x86_64-Linux/local/lib/python2.6/site-packages/sage/numerical/optimize.py", line 415, in minimize_constrained
    return vector(RDF,min)
UnboundLocalError: local variable 'min' referenced before assignment

It comes from the following piece of code:

K = matrix(K) # matrix of size (3*N+1)*(3*N+1)
des = vector(des) # vector of size 3*N+1

u = vector([var("u%02d" % k) for k in [0..3*N]]) # size 3*N+1

def LHS(X):
    Y = 0.5*K*X*X - vector(des)*X
    return Y

nul = [0 for j in range(0,3*N+1)]
minimize_constrained(LHS(u), [u02 -1], nil)

I don't understand why I keep getting the error for above function call (I know about global/local variables in python function calls, but definition of vector "u" makes it's elements global variables.)