Dear Scott,
Thanks for posting. On Oct 15, 6:46 pm, Scott <spectre...@gmail.com> wrote: > I know this is really basic, but for some reason I cannot figure this > out and my searching (here, sage website, google, etc) has not yielded > me any results! I just started using sage, literally, yesterday. > > I am using solve() to solve an equation for q1 in terms of q2. The > solution of this is saved, but when I print it, it prints as an exact > answer, but I want it in decimal/approximate form. I have tried using > the n() function, but I get an error when trying it. > > Here is an example: > -------------------------------------------------- > q1, q2 = var('q1, q2') > r = 0.60 > t1 = 0.005 > t2 = 0.007 > d = 2.0 > A1 = (1/2)*pi*r*r > A2 = (1/2)*d*(2*r) > theta1 = 1/(2*A1)*(q1*2*pi*r/t1+(q1-q2)*2*r/t1) > theta2 = 1/(2*A2)*(q2*d/t2+q2*sqrt(d^2+(2*r)^2)/t2+(q2-q1)*2*r/t1) > sol_q1 = solve([theta1==theta2], q1) > print sol_q1 > print sol_q1[0].substitute(q2=1).right().n() > -------------------------------------------------- > > When this is run, the result for sol_q1 is: q1 = (223317 pi + 416000)/ > ((223317 pi + 416000) q2)*q2 > The last line does work to give me the desired value (0.58239....), > but this is definitely not an ideal way of getting it! And of course > this wouldn't work for a more complicated result (since I use q2=1). > Why not? You should be able to put whatever you want in for q2. Maybe I am misunderstanding the question. > I've tried many other combinations of sol_q1.n(), sol_q1[0].n(), etc, All these will do nothing if you haven't specified q2, because you are trying to approximate something which has no approximation; you have to substitute all free variables before approximating. I suppose it would be possible to make Sage do everything on coefficients, but I don't think that is the usual functionality. Your solution is actually pretty good; even doing .substitute(q2=1.0) wouldn't help, because we prefer to leave pi unapproximated until necessary. I do agree that it's annoying! But I'm not sure how to make it less so, short of writing another function that evaluated a symbolic equation at a given point - without checking that you had something like sage: solve([sin(x-y)==x*y],y) [y == -sin(-x+y)/x] where it would cause trouble. Hope this helps! - 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 -~----------~----~----~----~------~----~------~--~---