Coverage for docs/source/examples/evaluated_free_variables.py: 100%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

7 statements  

1"Example post-solve evaluated variable" 

2from gpkit import Variable, Model 

3 

4# code from t_constraints.test_evalfn in tests/t_sub.py 

5x = Variable("x") 

6x2 = Variable("x^2", evalfn=lambda v: v(x)**2) 

7m = Model(x, [x >= 2]) 

8m.unique_varkeys = set([x2.key]) 

9sol = m.solve(verbosity=0) 

10assert abs(sol(x2) - 4) <= 1e-4