Well, can't you just do expr.subs(f, sin(x))? subs should work for anything (assuming it makes sense).
Or maybe I still don't understand what you want to do. Aaron Meurer On Sep 7, 2010, at 10:45 AM, Rahul Siddharthan wrote: > On Tue, Sep 7, 2010 at 9:21 PM, Aaron S. Meurer <asmeu...@gmail.com> wrote: >> I don't think it's possible to substitute just theta without concern for x, >> but this should work >> >> In [9]: f = Function('theta')(x) >> >> In [10]: f >> Out[10]: θ(x) >> >> In [11]: expr = 6*f + x >> >> In [12]: expr >> Out[12]: x + 6⋅θ(x) >> >> In [13]: g = Function('beta')(x) >> >> In [14]: g >> Out[14]: β(x) >> >> In [15]: expr.subs(f, g) >> Out[15]: x + 6⋅β(x) > > OK, but that just gets me from theta to beta... can I substitute an > actual function, like sin? > > But it doesn't matter -- I just realised I don't actually need it > (though it would be nice to have it). > > The situation is this: my implementation of SICM lets me calculate the > Lagrangian, the Lagrange equations, and the "first-order" Lagrange > equations for any Lagrangian. For example, for the harmonic > oscillator I get the first order equations (functions to be equated to > zero): > -v(t) + D(x(t), t) > (k*x(t) + m*D(v(t), t))/m > (equating each to zero, the first just defines the velocity and the > second is Newton's law.) > > Now it would be nice to use these equations (or rather, equations for > less trivial systems) in an integrator, but that requires substituting > values for x(t) and v(t). But I can actually get equivalent equations > in terms of symbols x and v, rather than functions x(t) and v(t), via > a rather clever procedure in SICM called Gamma_bar -- and that is > preferable for the integrator, anyway. > > Thanks, > > Rahul -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sy...@googlegroups.com. To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.