Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Numerical approximation of symbolic equation

What I would like to do is the following:

var('theta')

theta

theta=25*units.angles.degree

print theta

25*degree

a=sin(theta)

print a

sin(25*degree)

At this point, I type 'a.' and tab and in the popup list of functions I find numerical_approx. So I type in:

a.numerical_approx() Traceback (click to the left of this block for traceback)

...

TypeError: cannot evaluate symbolic expression numerically

Okay, it would appear that adding the units to theta turns it into a symbolic variable which turns my expression a into a symbolic expression. But what I would like to do is enter my angle theta in either degrees or radians and get a numerical approximation of the answer based on the units of the input. Is there a clean way to do this?

click to hide/show revision 2
No.2 Revision

Numerical approximation of symbolic equation

What I would like to do is the following:

var('theta')

sage: var('theta')
theta

theta=25*units.angles.degree

sage: theta=25*units.angles.degree sage: print theta

theta
25*degree

a=sin(theta)

sage: a=sin(theta) sage: print a

a
sin(25*degree)

At this point, I type 'a.' and tab and in the popup list of functions I find numerical_approx. So I type in:

sage: a.numerical_approx()
 Traceback (click to the left of this block for traceback)

traceback)
...
 TypeError: cannot evaluate symbolic expression numerically

Okay, it would appear that adding the units to theta turns it into a symbolic variable which turns my expression a into a symbolic expression. But what I would like to do is enter my angle theta in either degrees or radians and get a numerical approximation of the answer based on the units of the input. Is there a clean way to do this?