# how to convert a named function to sympy i know from another question, that

sage: x = var('x')
sage: y = 2 * x + Ei(x)
sage: import sympy
sage: sympy.sympify(y)
2*x + Ei(x)
sage: type(_)


or

sage: x = var('x')
sage: y = 2 * x + Ei(x)
sage: y._sympy_()
2*x + Ei(x)


works. But how can i convert a equation named for example d to sympy.

var('r h s phi theta d')

s_v=vector([s*cos(theta),-s*sin(theta)])
h_v=vector([h*sin(phi),-h*cos(phi)])
r_v=vector([r*cos(phi),r*sin(phi)])

f_v=r_v+h_v-s_v

def f(r,h,s,phi,theta): return norm(f_v(r=r,h=h,s=s,phi=phi,theta=theta))

d=f(r,h,s,-phi,theta)-f(r,h,s,0,theta)

import sympy
sympy.sympify(d)
d


i also tried to do

from sympy import sympify
from sympy.solvers import solve
solve(sympify(d),r)


but than he is telling me

Traceback (click to the left of this block for traceback)
...
NotImplementedError: SymPy function 'abs' doesn't exist


:'(

thank you a lot

Thank you guys. I can´t find a Sage 6.4 Beta3 Version vor VM. I downloaded this . Is it somehow possible, to use this folder to run in through a VM. I have no experience with that and as far as i know until yet do i need a *.ova file.

I now tried in sage 6.3

d = abs(f_v.subs(phi=-phi))-abs(f_v.subs(phi=0))

from sympy import sympify
from sympy.solvers import solve
#sympy.sympify(d)
solve(sympify(d),r)


solve it for theta works now, wich is a big step forward, thank you for that! But for any other variable for example r is the result: [] for d it is :  should there just come the equation for d?

Does this mean, that sage can´t solve this equation or, that i still do something wrong?

edit retag close merge delete

The 6.4.beta3 tarball you downloaded is Sage's source code, which must be compiled, so you need to run GNU/Linux or some other POSIX compliant system to do this. If you are using the VM through windows, it is much less easy, so it is preferable to wait for the official Sage 6.4, that will propose .ova images. It is never too late to switch to GNU/Linux :)

Sort by » oldest newest most voted Something like that maybe ?

sage: d = abs(f_v.subs(phi=-phi))-abs(f_v.subs(phi=0))
sage: sympy.sympify(d)
-sqrt((-h + s*sin(theta))**2 + (-r + s*cos(theta))**2) + sqrt((-h*sin(phi) + r*cos(phi) - s*cos(theta))**2 + (h*cos(phi) + r*sin(phi) - s*sin(theta))**2)

more

The problem comes from the fact that Sage does not know that its own abs should be translated into sympy.Abs (see the upper case). This has been fixed in trac ticket 15057, and merged today in Sage 6.4.beta3. Your options are:

• compile Sage 6.4.beta3
• wait for Sage 6.4 official release
• let sympy know about abs

sage: import sympy
sympy.abs = sympy.Abs


In you last line, you will get (i did not check it it the expected result though):

sage: sympy.sympify(d)
-sqrt(Abs(-h + s*sin(theta))**2 + Abs(r - s*cos(theta))**2) + sqrt(Abs(-h*sin(phi) + r*cos(phi) - s*cos(theta))**2 + Abs(-h*cos(phi) - r*sin(phi) + s*sin(theta))**2)

more