Aaron S. Meurer wrote:
So apparently f is not a Function (I had to guess, since I couldn't reconstruct your expression from the code you posted).
Another way to accomplish this would be to substitute D(g(tau), tau)**2 with 1
- D(f(tau), tau)**2 (a similar trick is useful for simplifying expressions with
sin(x)**2 and cos(x)**2 in them).
Aaron Meurer
On Apr 25, 2010, at 8:49 PM, Alan Bromborsky wrote:
Aaron S. Meurer wrote:
I think the problem is that you use f.diff(tau) instead of f(tau).diff(tau).
The first evaluates to 0, because it doesn't know that f depends on tau.
Aaron Meurer
On Apr 25, 2010, at 6:02 PM, Alan Bromborsky wrote:
Here is code -
dRdtau = R.diff(tau)
print 'e_tau =',dRdtau
dRdtau_sq = (dRdtau|dRdtau)()
print 'e_tau^2 =',dRdtau_sq
dRdtau_sq = trigsimp(simplify(dRdtau_sq))
print 'e_tau^2 =',dRdtau_sq
dRdtau_sq.subs((g.diff(tau))**2-(f.diff(tau))**2,1)
print 'e_tau^2 =',dRdtau_sq
Here is output -
e_tau =
D(g(tau),tau)*e0+(D(f(tau),tau)*cos(th(tau,xth))-D(th(tau,xth),tau)*f(tau)*sin(th(tau,xth)))*e1+(D(f(tau),tau)*sin(th(tau,xth))+D(th(tau,xth),tau)*cos(th(tau,xth))*f(tau))*e2
e_tau^2 = D(g(tau), tau)**2 - (D(f(tau), tau)*cos(th(tau, xth)) - D(th(tau,
xth), tau)*f(tau)*sin(th(tau, xth)))**2 - (D(f(tau), tau)*sin(th(tau, xth)) +
D(th(tau, xth), tau)*cos(th(tau, xth))*f(tau))**2
e_tau^2 = D(g(tau), tau)**2 - D(f(tau), tau)**2 - D(th(tau, xth),
tau)**2*f(tau)**2
e_tau^2 = D(g(tau), tau)**2 - D(f(tau), tau)**2 - D(th(tau, xth),
tau)**2*f(tau)**2
A constraint is that -
D(g(tau), tau)**2 - D(f(tau), tau)**2 = 1
My use of subs does not do that. How can I make such a substitution?
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.
Revised code -
dRdtau_sq.subs((diff(g(tau),tau))**2-(diff(f(tau),tau))**2,1)
Result -
dRdtau_sq.subs((diff(g(tau),tau))**2-(diff(f(tau),tau))**2,1)
File
"/usr/local/lib/python2.6/dist-packages/sympy-0.6.7_git-py2.6.egg/sympy/core/basic.py",
line 1309, in __call__
raise TypeError("argument must be a dictionary")
TypeError: argument must be a dictionary
Revised code again -
dRdtau_sq.subs({(diff(g(tau),tau))**2-(diff(f(tau),tau))**2:1})
Result -
dRdtau_sq.subs({(diff(g(tau),tau))**2-(diff(f(tau),tau))**2:1})
File
"/usr/local/lib/python2.6/dist-packages/sympy-0.6.7_git-py2.6.egg/sympy/core/basic.py",
line 1309, in __call__
raise TypeError("argument must be a dictionary")
TypeError: argument must be a dictionary
More suggestions please.
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.
Here is the entire program -
#!/usr/bin/python
import sys
import os,sympy,time
from sympy import *
from sympy.galgebra.GA import *
from sympy import collect
set_main(sys.modules[__name__])
if __name__ == '__main__':
make_symbols('tau xth dg df dg2 df2')
metric = '1 0 0, 0 -1 0, 0 0 -1'
MV.setup('e0 e1 e2',metric)
f = Function('f')(tau)
g = Function('g')(tau)
th = sympy.Function('th')(tau,xth)
R = g*e0+f*(cos(th)*e1+sin(th)*e2)
dRdxth = R.diff(xth)
print 'dR/dxth =',dRdxth
dRdxth_sq = (dRdxth|dRdxth)()
print 'e_xth^2 =',dRdxth_sq
dRdxth_sq = sympy.trigsimp(dRdxth_sq)
print 'e_xth^2 =',dRdxth_sq
dRdtau = R.diff(tau)
print 'e_tau =',dRdtau
dRdtau_sq = (dRdtau|dRdtau)()
print 'e_tau^2 =',dRdtau_sq
dRdtau_sq = trigsimp(simplify(dRdtau_sq))
print 'e_tau^2 =',dRdtau_sq
dRdtau_sq.subs(g.diff(tau)**2,1+f.diff(tau)**2)
print 'e_tau^2 =',dRdtau_sq
Here is output -
dR/dxth =
-D(th(tau,xth),xth)*f(tau)*sin(th(tau,xth))*e1+D(th(tau,xth),xth)*cos(th(tau,xth))*f(tau)*e2
e_xth^2 = -D(th(tau, xth), xth)**2*cos(th(tau, xth))**2*f(tau)**2 -
D(th(tau, xth), xth)**2*f(tau)**2*sin(th(tau, xth))**2
e_xth^2 = -D(th(tau, xth), xth)**2*f(tau)**2
e_tau =
D(g(tau),tau)*e0+(D(f(tau),tau)*cos(th(tau,xth))-D(th(tau,xth),tau)*f(tau)*sin(th(tau,xth)))*e1+(D(f(tau),tau)*sin(th(tau,xth))+D(th(tau,xth),tau)*cos(th(tau,xth))*f(tau))*e2
e_tau^2 = D(g(tau), tau)**2 - (D(f(tau), tau)*cos(th(tau, xth)) -
D(th(tau, xth), tau)*f(tau)*sin(th(tau, xth)))**2 - (D(f(tau),
tau)*sin(th(tau, xth)) + D(th(tau, xth), tau)*cos(th(tau, xth))*f(tau))**2
e_tau^2 = D(g(tau), tau)**2 - D(f(tau), tau)**2 - D(th(tau, xth),
tau)**2*f(tau)**2
e_tau^2 = D(g(tau), tau)**2 - D(f(tau), tau)**2 - D(th(tau, xth),
tau)**2*f(tau)**2
Note that both f and g are defined as functions. Could the problem be
in substituting a function of a derivative of a general fuction?
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.