maybe it helps if i give my full pice of code: def calc_wights_by_sum_to_zero(s): #create the equations variables = [var("w" + str(i),domain=ZZ)for i in range(s.nvertices())] equation = reduce(lambda f1,f2: f1 + f2, [variables[i] * s.vertex(i) for i in range(s.nvertices())]) #calculate the result, containing a parameter r result = solve(equation,variables)[0] #get the name of the parameter parameter = result[0].variables()[0]
#add the constrain r == 1 result.append(parameter == 1) variables.append(parameter) #get the result for r = 1 result = solve(result,variables) return tuple( [ww.right_hand_side() for ww in result[0]][0:-1]) i know that the equations are always solveable in ZZ. greatz Am 30.07.2010 02:03, schrieb kcrisman: > > On Jul 29, 6:01 pm, Johannes <dajo.m...@web.de> wrote: > >> Hi list, >> i try to solve a linear equation in ZZ in the variables w_i: >> >> sage: variables = [var("w" + str(i),domain=ZZ)for i in range(s.nvertices())] >> sage: eq >> (w0 + w1 + w2 - 14*w3, w1 + 2*w2 - 8*w3, 2*w2 - 3*w3) >> sage: result >> [w0 == 15/2*r548, w1 == 5*r548, w2 == 3/2*r548, w3 == r548] >> >> up to here it's ok, but now im lookin for the smalest integer r548 > 0 >> solving this equatoins. in other words, the smalest r548 such that every >> wi is in ZZ. >> How can i do this? >> > This sounds sort of like integer programming, which is very tough in > general. Although in this case r548=2 looks like it would give all > integer wi, just by inspection. Presumably this wouldn't always be > possible with whatever you are looking at, though. I suppose one > could just do > > r548=1 > while all wi not integers: > r548+=1 > > or something, though obviously that's a hack. > > Another issue is that solve() does not actually take the domain into > account necessarily. (In fact, I'm not sure what var(domain=blah) > does, but someone else may want to clarify that.) At any rate, Maxima > (which does our solving) is explicitly designed not to take > assumptions of this kind into account - though, again, I don't know > that domain=ZZ would pass that on to Maxima anyway; presumably this is > a Pynac thing. > > Does anyone else have ideas for this? > - kcrisman > > -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org