I would like to determine the equation in the equilibrium position.

eq = 1/2 g l m Cos[θ[t]] == J (θ^′′)[t]
1/2 g l m Cos[θ[t]] == J (θ^′′)[t]
Subscript[proc, e][eq_] := Replace[eq, θ[t] -> θe, ∞]
Subscript[proc, e][eq]
1/2 g l m Cos[θe] == J (θ^′′)[t]

Equation at the equilibrium position with mathematica

Unfortunately, the second derivative of theta[t] is not equal to 0 and so I don't obtain the equation for the equilibrium position.

In maple, as you can see in the following picture, I manage to have the good result.

Equation at the equilibrium position with maple

Can anyone help me to correct my Mathematica code in order to obtain the equation at the equilibrium position?


1 Answer 1


By replacing using the rule:

θ[t] -> θe

You are replacing all instances of the expression θ[t]. However, the derivative θ''[t] is represented in Mathematica by:


(You can see this by using FullForm.) This does not contain θ[t], so no replacement is performed. What you want to do is replace θ with a Function like this:

θ -> Function[t, θe]
θ -> (θe &)

When substituting this into your expression, Derivative will be able to evaluate the derivative of the function, which is zero.

Two comments on your code: you probably want to be using ReplaceAll like this:

processEquation[eq_] := ReplaceAll[eq, θ -> (θe &)]
processEquation[eq_] := eq /. θ -> (θe &)

Instead of using Replace. Second, you generally shouldn't SetDelayed to expressions with the Head Subscript. That associates the definition of your function with Subscript. You can see that from the results of Definition[Subscript]:

Attributes["Subscript"] = {NHoldRest}

Subscript[proc, e][eq_] := Replace[eq, θ[t] -> θe,  ∞]

Trying to Set instead of SetDelayed will produce an error, since Subscript is protected. Use non-subscripted names instead, like I did above.

  • $\begingroup$ Thank for your help. 1) However, may you detail me these codes lines ? θ -> Function[t, θe] θ -> (θe &) I have difficulties to understand these lines. Isn't there another simplest solution to replace the function theta[t] by a constant as thetae ? $\endgroup$
    – Bendesarts
    Feb 26, 2015 at 16:38
  • $\begingroup$ Read the documentation for Function. Both lines define a rule from θ to a function (Function[t, θe] or θe &) that returns a constant, θe, given any argument. The function processEquation applies this rule to its argument. This is the simplest solution (except for simply applying the rule directly to your equation). $\endgroup$ Feb 26, 2015 at 16:56
  • $\begingroup$ OK Thank you for your clear explanations. May you precise me the difference between Replace with infinity in argument and ReplaceAll? Which should I use for my objective ? $\endgroup$
    – Bendesarts
    Feb 26, 2015 at 17:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.