Ask Your Question

Evaluate expression with unknowns

asked 2013-02-18 07:59:38 -0500

adamhg gravatar image

updated 2015-01-14 07:28:46 -0500

FrédéricC gravatar image

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 flag offensive close merge delete

2 answers

Sort by » oldest newest most voted

answered 2013-02-19 03:17:14 -0500

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)
edit flag offensive delete link more


nice! this really seems to solve the question.

twch gravatar imagetwch ( 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.

adamhg gravatar imageadamhg ( 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.

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

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

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

answered 2013-02-18 08:57:09 -0500

twch gravatar image

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']


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?

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-02-18 07:59:38 -0500

Seen: 134 times

Last updated: Feb 19 '13