Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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(_)
<class 'sympy.core.add.Add'>

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

thank you a lot

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(_)
<class 'sympy.core.add.Add'>

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

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(_)
<class 'sympy.core.add.Add'>

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 : [0] 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?

click to hide/show revision 4
retagged

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(_)
<class 'sympy.core.add.Add'>

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 : [0] 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?