Mathematica Globally Define Variable as Real

  • Mathematica
  • Thread starter teroenza
  • Start date
  • #1
195
5
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?
 

Answers and Replies

  • #2
DrClaude
Mentor
7,540
3,873
Using $Assumptions should work. You will need to give a specific example if you want more help.
 
  • #3
195
5
Code:
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:
Re[(x + I y)^2 Sin[\[Theta]/2]^2]

Re[(x + I y)^2] Sin[\[Theta]/2]^2
 
  • #4
DrClaude
Mentor
7,540
3,873
I see. You need to do also a ComplexExpand:
Code:
Assuming[x \[Element] Reals && y \[Element] Reals && \[Theta] \[Element] Reals, 
Simplify[ComplexExpand[Re[(x + I y)^2 Sin[\[Theta]/2]^2]]]]
 

Related Threads on Mathematica Globally Define Variable as Real

Replies
6
Views
6K
Replies
1
Views
2K
Replies
4
Views
5K
Replies
1
Views
7K
Replies
2
Views
2K
Replies
4
Views
6K
Replies
8
Views
3K
Top