Evaluate expression with unknowns

I'm trying to evaluate an integral that comes out with a crazy long result. I'm not going to paste it here because it really is quite long, which is essentially the problem. The result actually only has a few instances of unknowns in it, 90% of it's length comes from un-evaluated constants (like 2^(1/7), log(11.5), stuff like that). So it sort of looks like:

f(x) = (x* 2* pi* log(5)* 6^1.5) / (3^4*pi^2+x)

except it spans 10 lines.

If I could get sage to just express all of that stuff as a solid number, then the resulting expression wouldn't be so prohibitively long (I think it would actually evaluate out to something similar to the example I gave, number*x/(number+x) ). But numerical_approx() won't take anything with unknowns in it, so I can't just plug that expression into n().

How does one evaluate the knowns in an expression that contains unknowns?

Thank you ahead of time for your help!

edit retag close merge delete

Sort by » oldest newest most voted

You need the ._convert() method:

sage: f = (x* 2* pi* log(5)* 6^1.5)/(3^4*pi^2+x)
sage: f._convert(RR)
148.621271129886*x/(x + 799.437956488238)

more

nice! this really seems to solve the question.

( 2013-02-19 03:41:53 -0500 )edit

Aha! This is exactly what I needed, thank you. Thank you @tobias-weich as well, you are right though my final expression wasn't just a polynomial or a division of polynomials.

( 2013-02-19 10:11:29 -0500 )edit

you might then mark burcin's answer as a solution by clicking on the check mark in order to show to the others, that this question is solved.

( 2013-02-19 11:00:59 -0500 )edit

@burcin - should this be a non-underscore function, then?

( 2013-02-20 03:34:55 -0500 )edit

Mh interesting question. I'm sure that I will not answer it completely satisfactory, but for the example that you have given, the following works:

f= (x* 2* pi* log(5)* 6^1.5)/(3^4*pi^2+x)
R = RR['x']
FR=Frac(R)
FR(f)


returns

148.621271129886*x/(x + 799.437956488238)


The idea behind it is to convert the symbolic expression to the fractional field of polynomials with coefficiants in the real numbers. This however fails as soon as the expression you like to simplify is not a rational function anymore, i.e. as soon as some squareroots or trigonometric functions appear. So what else can be done?

more