Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mathematica Globally Define Variable as Real

  1. Nov 3, 2014 #1
    I want to write a line of code at the top of my .nb and have Mathematica treat the specified variables as real only. I've tried using "Assumptions" and "Assuming", but it just won't work. I still get back answers where the entire expression is returned inside the Re[ ] command, like it is confused over which variables might have imaginary parts.

    Can it just be defined somehow globally that {x,y,z} are real only?
     
  2. jcsd
  3. Nov 4, 2014 #2

    DrClaude

    User Avatar

    Staff: Mentor

    Using $Assumptions should work. You will need to give a specific example if you want more help.
     
  4. Nov 4, 2014 #3
    Code (Text):
    Assuming[x \[Element] Reals && y \[Element] Reals && \[Theta] \[Element] Reals,Re[(x + I y)^2 Sin[\[Theta]/2]^2]]

    Simplify[Re[(x + I y)^2 Sin[\[Theta]/2]^2],Assumptions ->  x \[Element] Reals &&   y \[Element] Reals && \[Theta] \[Element] Reals]
    returns
    Code (Text):
    Re[(x + I y)^2 Sin[\[Theta]/2]^2]

    Re[(x + I y)^2] Sin[\[Theta]/2]^2

     
     
  5. Nov 5, 2014 #4

    DrClaude

    User Avatar

    Staff: Mentor

    I see. You need to do also a ComplexExpand:
    Code (Text):

    Assuming[x \[Element] Reals && y \[Element] Reals && \[Theta] \[Element] Reals,
    Simplify[ComplexExpand[Re[(x + I y)^2 Sin[\[Theta]/2]^2]]]]
     
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook