Yes, that is exactly what I want...fractions/pi/etc to auto-
approximate.  Or they don't even have to "auto" approximate, but if I
can just call a function that THEN approximates the fractions, pi,
etc.  After I re-read my first post, it definitely wasn't very
clear :)  But now you know.  I wouldn't think this would be that
difficult to implement?  Just have a function that approximates the
function?  I have no knowledge of the sage internals though outside of
scipy/numpy though...Thanks for the help, and please give more input
if anyone has any.

On Oct 15, 6:00 pm, kcrisman <kcris...@gmail.com> wrote:
> On Oct 15, 8:31 pm, Scott <spectre...@gmail.com> wrote:
>
>
>
> > What I really want is sage to give me the answer as:
> > q1 = 0.58239...(however many digits)*q2
>
> > Is there a way to do that?  I don't want an approximate value of the
> > entire thing (obviously you can't get that without giving the value of
> > q2), but I want it to compute whatever it can (in this case that
> > (223317 pi + 416000)/(223317 pi + 416000) = 0.58239...
>
> > Note:
> > An error in my first post:
> > When this is run, the result for sol_q1 is: q1 = (223317 pi + 416000)/
> > ((223317 pi + 416000) q2)*q2
> > SHOULD BE:
> > When this is run, the result for sol_q1 is: q1 = (223317 pi + 416000)/
> > (223317 pi + 416000)*q2
> > What I want:
> > q1 = 0.58239...*q2
>
> I see.  So what you want is for things like pi to autoevaluate, or (if
> pi wasn't present), for fractions to auto-approximate.  That is, if
> you got
>
> q1 == (3/4)*q2
>
> you'd want n() to give you
>
> q1 == 0.7500000...*q2
>
> Is that right?  Technically, you could access the individual
> coefficients in .rhs() (via things like .coefficients and .pyobject, I
> think) and apply n() to them all equations, as in the for loop you
> mention earlier.  That might be a lot of work, I'm not sure.
>
> I suppose that now that our symbolic expressions are all tree-based,
> it's conceivable that this could be implemented.  I don't know if it's
> advisable.  Burcin, Mike, others... any thoughts?  I have a feeling
> that could be dangerous for internal reasons.
>
> - kcrisman
>
>
>
> > On Oct 15, 5:16 pm, kcrisman <kcris...@gmail.com> wrote:
>
> > > 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to