4
$\begingroup$

I have a code that will output an expression in form of a functions like this

(Λ[θ]^3 Ω[θ] - 4 (3 Derivative[1][Λ][θ] Derivative[1][Ω][θ] + Ω[θ] ( Λ′′)[θ]) - 
 4 Λ[θ] (Ω[θ] + 3 (Ω′′)[θ]))/(4 G J Λ[θ] Ω[θ]^3)

Now, I have functions $\Lambda(\theta)$ and $\Omega(\theta)$, that I'd like to replace with some values of theta. I tried with -> and :> and none of the replacement rules will differentiate my replacement. I can differentiate the variables separately, and then specify replacement rule Λ'[θ] -> value(θ), and then use /. Derivative[1][Λ][θ]-> value[θ], but that seems kinda redundant.

Why isn't Mathematica doing it on it's own, recognising that it is the same expression, and just evaluating the derivative? This way Mathematica is treating differentiated lambdas or omegas as something not connected to original lambda and omega.

Why is this so, and can it be circumvented?

$\endgroup$
1
  • 1
    $\begingroup$ If you can't install the script don't use Greek letters ... it isn't that hard $\endgroup$ Nov 1, 2013 at 14:40

1 Answer 1

5
$\begingroup$

I hope I understood correctly what you try to do... Assume the following simple example where you have derivatives

expr=Expand[(D[f[x],{x,2}]+f[x])^3]
(* f[x]^3+3 f[x]^2 f''[x]+3 f[x] f''[x]^2+f''[x]^3 *)

The problem you are facing is that you want to apply a rule like

f[x_] :> Cos[x]*Sin[x]

This will not work on the derivatives because there FullForm does not match the lhs of the rule. What you probably want is to

  1. replace the head f with your function
  2. replace all x with the value

Therefore, if you know your function f[x] is now Cos[x]*Sin[x] you can do

expr /. f -> (Sin[#]*Cos[#] &)

(* -27 Cos[x]^3 Sin[x]^3 *)

and then you replace the value for x

% /. x->Pi
(* 0 *)
$\endgroup$
3
  • $\begingroup$ This one expr /. f -> (Sin[#]*Cos[#] &) is what I needed! Now it works :) Thank you very much :) I was wondering if it's because the FullForm expression for each one isn't the same and that is making an issue, and I guess it's true. Thanks again :) $\endgroup$
    – dingo_d
    Nov 2, 2013 at 8:11
  • 1
    $\begingroup$ Yes, when you replace something, you should always look at the FullForm when something doesn't work as you like it. $\endgroup$
    – halirutan
    Nov 2, 2013 at 9:53
  • $\begingroup$ I'll have that in mind in the future :) Thanks $\endgroup$
    – dingo_d
    Nov 3, 2013 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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