ankur see attached -

A symbol is not a function.  For example if you want A to be a general
function of symbols x, y, z your write -

A = Function('A')(*(x,y,z))

don't ask me to explain the syntax I just use it.

On Tue, Mar 21, 2017 at 2:52 PM, Mikayla Grace <[email protected]>
wrote:

> @brombo, I definitely agree there should be a system in place for easy
> conversion. I was thinking about allowing a user to input in whatever
> coordinate system they wanted but when implementing functions the vectors
> would get converted into rectangular coordinates, pushed through the
> function, and then converted back to the original coordinate system and
> returned. The functions already handle Cartesian coordinates so this would
> cut down on work and internal redundancy (i.e. we would avoid defining the
> functions again with different coordinate systems).
>
> @ankur, Awesome, I'll take a closer look at it. Thanks for sharing! My
> general plan was to closely parallel the existing class definition for
> Cartesian coordinates. I figured this would help keep things organized and
> clear.
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/sympy/72c0d30c-763f-4eab-bfb3-7aa50be61722%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CALOxT-nnevGuVNOzAxoCb%3DzcP%3Djtxdefk5Sy1g8ypcocc26Etw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
from sympy import *
from sympy.vector import *
C = CoordSysCartesian('C')

r = Symbol('r', positive = True, real = True)
theta = Symbol('theta', positive = True)
phi = Symbol('phi')

#Defining Spherical Polar Coordinates in i, j, k space

R = r*sin(theta)*cos(phi)*C.i + r*sin(theta)*sin(phi)*C.j + r*cos(theta)*C.k
print R.components
print "Magnitude:" + str(simplify(sqrt(R.dot(R))))+"\n"

#h1, h2, h3 are scale factor for r, theta and phi respectively
h1 = diff(R,r)
h2 = diff(R, theta)
h3 = diff(R, phi)

#Scale Factors are Magnitude of Differentiation
print "Scale Factors:"+"\n"
h1 = simplify(sqrt(h1.dot(h1)))
print "for r^: "+ str(h1) +"\n"
h2 = simplify(sqrt(h2.dot(h2)))
print "for theta^: " + str(h2)+"\n"
h3 = simplify(sqrt(h3.dot(h3)))
print "for phi^: " + str(h3)+"\n"

#e1, e2, e3 are the new unit vectors for r, theta and phi respectively
print "Unit Vector in i, j, k Cartesian System"+"\n"
e1 = simplify(diff(R, r)/h1)
print "r^="+str(e1)+"\n"
e2 = simplify(diff(R, theta)/h2)
print "theta^="+str(e2)+"\n"
e3 = simplify(diff(R, phi)/h3)
print "phi^="+str(e3)+"\n"

#A = Ar r^ + At theta^ + Ap phi^
coords = (r,theta,phi)

#Ar, At, Ap = symbols('Ar At Ap')
Ar = Function('Ar')(*coords)
At = Function('At')(*coords)
Ap = Function('Ap')(*coords)

A = Ar*e1+At*e2+Ap*e3

new_coord = [r, theta, phi]
scale_factors = [h1, h2, h3]
unit_vectors = [e1, e2, e3]
h = h1*h2*h3

#Computing Divergence in New Coordinates
for i in range(0,3):
    print "Divergence in " + str(new_coord[i]) + " Component"
    multiplier = h/scale_factors[i]
    component = simplify(A.dot(unit_vectors[i]))*multiplier
    print str(diff(component, new_coord[i])/h)+"\n"

Reply via email to