Ask Your Question

Jannik's profile - activity

2019-03-17 17:40:59 +0200 received badge  Famous Question (source)
2018-05-03 00:18:34 +0200 received badge  Student (source)
2017-08-09 01:09:23 +0200 received badge  Popular Question (source)
2016-02-06 04:37:24 +0200 received badge  Notable Question (source)
2016-02-06 04:37:24 +0200 received badge  Popular Question (source)
2014-09-11 09:16:19 +0200 asked a question 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?

2014-09-10 17:29:40 +0200 received badge  Editor (source)
2014-09-10 17:25:14 +0200 answered a question how to solve this equation for several variables (with sympy?)

very nice, thank you! how can i convert an sage expression to an sympy expression? i`d like to create the equation in sage and than solve it with sympy or is there a better way? 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)) from sympy import * r,h,s,phi,theta,d=symbols('r h s phi theta d') eq = f from sympy.solvers import solve sol=solve(eq, h) sol1=sol[0]._sage_() sol1(s=1) (how can i revise my question?)

2014-09-10 12:30:53 +0200 asked a question how to solve this equation for several variables (with sympy?)

Hi, I found some similar questions but i can´t solve my problem with these answers. I use sagemath since 2 days and want to investigate a equation in dependence for all variables for that i try to solve it for any variables:

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))


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

solve([eq1(r,h,s,phi,theta)==4],r)

so i want to solve this equation for r (and later for all other variables) but the solution is shitty like this:

[sqrt(abs(s*cos(theta) - r)^2 + abs(s*sin(theta) - h)^2) ==
sqrt(abs(-h*cos(phi) - r*sin(phi) + s*sin(theta))^2 + abs(-r*cos(phi) +
s*cos(theta) + h*sin(phi))^2) - 4]

so no r=...

as far as i understood does the solve command has problem with sqrt() so i found the sympy command in this forum and tried to use like this(for me its not possible to take the equation befor the sympy announcement so i wrote an other example by hand:

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))

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


from sympy import *            
r,h,s,phi,theta,d=symbols('r h s phi theta d') 

eq1= sqrt(r^2+h^2+s^2+2*s*cos(theta)*(-r*cos(phi)-h*sin(phi))+2*s*sin(theta)*(r*sin(phi)-h*cos(phi))) 

from sympy.solvers import solve
solve(eq1, h)

But now i can´t variate the variables.

That is a very long question, it would be very nice if some of you make the afford and have a look at this. Thank you very much for this

very nice, thank you! how can i convert an sage expression to an sympy expression? i`d like to create the equation in sage and than solve it with sympy or is there a better way?

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))

from sympy import *   

r,h,s,phi,theta,d=symbols('r h s ...
(more)