First off, make sure not to have 9/2, as Python converts this into a Float.
Use Rational(9, 2) or S(9)/2.
What is your r? It works for me:
In [10]: r = Symbol('r')
In [11]: f = j*(3*x**4 + 6*x**2*y**2 - 24*x**2*z**2 + 3*y**4 - 24*y**2*z**2
+ 8*z**4)/(2*(x**2 + y**2 + z**2)**(9/2))
In [12]: print(f.subs(sqrt(x**2+y**2+z**2),r))
j*(3*x**4 + 6*x**2*y**2 - 24*x**2*z**2 + 3*y**4 - 24*y**2*z**2 +
8*z**4)/(2*r**9)
I suspect you need to read
http://docs.sympy.org/latest/tutorial/gotchas.html.
Aaron Meurer
On Sun, Apr 6, 2014 at 11:35 AM, Dave M <[email protected]> wrote:
> Thanks for responding Aaron. Here is the relevant part of my session for
> the attempted r substitution. Can you tell me what I'm doing incorrectly
> and how to do it right?
>
> In [113]: f = j*(3*x**4 + 6*x**2*y**2 - 24*x**2*z**2 + 3*y**4 -
> 24*y**2*z**2 + 8*z**4)/(2*(x**2 + y**2 + z**2)**(9/2))
>
> In [114]: f
> Out[114]: j*(x**2 + y**2 + z**2)**(-4.5)*(3*x**4 + 6*x**2*y**2 -
> 24*x**2*z**2 + 3*y**4 - 24*y**2*z**2 + 8*z**4)/2
>
> In [115]: f.subs(sympy.sqrt(x**2+y**2+z**2),r)
> Out[115]: j*(x**2 + y**2 + z**2)**(-4.5)*(3*x**4 + 6*x**2*y**2 -
> 24*x**2*z**2 + 3*y**4 - 24*y**2*z**2 + 8*z**4)/2
>
>
>
>
> --
> 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 http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/ddbe9b1a-6d54-406d-a8c5-d62f2c158bb7%40googlegroups.com<https://groups.google.com/d/msgid/sympy/ddbe9b1a-6d54-406d-a8c5-d62f2c158bb7%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> 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 http://groups.google.com/group/sympy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/CAKgW%3D6J7hCR2paYLkTne5PYOhBxdD8RdZieBeDk-e4nF%2BcVJYQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.