This works, though it would have been nicer if epsilon actually
equalled what it was replacing. I just tried

(-1/2*(1/R^2 - beta_0/(R^2*beta))*sigma(r)^2).subs((1/R^2 - beta_0/
(R^2*beta))==epsilon)

which works, where

(-1/2*(1/R^2 - beta_0/(R^2*beta))*sigma(r)^2).subs((1/2)*(1/R^2 -
beta_0/(R^2*beta))==epsilon)

does not. So I guess there's an upper limit to the number of
operations that the expression being replaced can have to work in subs
().


On Oct 8, 12:52 pm, Francois Maltey <fmal...@nerim.fr> wrote:
> Ranjit a écrit :
>
>
>
> > I'm trying to figure out how to do a simple substitution. I've the
> > following code:
>
> > var('r beta beta_0 R a h')
> > psi=function('psi',r)
> > sigma=function('sigma',r)
>
> > H_0=function('H_0',r)
>
> > H_grad = lambda psi : (1/2)*(beta/beta_0)*R^2*(psi.diff(r))^2
> > H_0(psi) = -(1/2)*(beta/beta_0-1)*psi^2 + beta*a*psi^4 + beta*h*psi
>
> > H_1=H_grad((1/R)*(beta_0/beta)^(1/2)*sigma)
> > H=H_1+H_0((1/R)*(beta_0/beta)^(1/2)*sigma)
>
> > H=H.simplify_radical().expand().collect(sigma^2)
> > H
>
> The formula.subs_expr (equation) doesn't recognize all sub-product or
> all sub-sum, but recognize ONE term in a sum, even a complex one, so I
> test with succes the code :
>
> coef = H.coefficient(sigma(r), 2)
> H.subs_expr(coef*sigma(r)^2==epsilon*sigma(r)^2)
>
> epsilon*sigma(r)^2 + sqrt(beta)*sqrt(beta_0)*h*sigma(r)/R +
> a*beta_0^2*sigma(r)^4/(R^4*beta) + 1/2*D[0](sigma)(r)^2
>
> Do I answer to your question ?
>
> F.
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to