Ask Your Question
2

Evaluate expression with unknowns

asked 2013-02-18 14:59:38 +0100

adamhg gravatar image

updated 2015-01-14 14:28:46 +0100

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
4

answered 2013-02-19 10:17:14 +0100

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

Comments

nice! this really seems to solve the question.

twch gravatar imagetwch ( 2013-02-19 10:41:53 +0100 )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 17:11:29 +0100 )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 18:00:59 +0100 )edit

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

kcrisman gravatar imagekcrisman ( 2013-02-20 10:34:55 +0100 )edit
1

answered 2013-02-18 15:57:09 +0100

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

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

Stats

Asked: 2013-02-18 14:59:38 +0100

Seen: 585 times

Last updated: Feb 19 '13