Mathematica Tips and Tricks

From Physiki
(Difference between revisions)
Jump to: navigation, search
 
 
(One intermediate revision by one user not shown)
Line 7: Line 7:
 
However, this does not solve all problems with complex numbers since you may need to have Mathematica perform operations with complex numbers but not use them in certain variables.  You can achieve this by including the package 'ReIm' and informing mathematica that a certain variable has no imaginary part:
 
However, this does not solve all problems with complex numbers since you may need to have Mathematica perform operations with complex numbers but not use them in certain variables.  You can achieve this by including the package 'ReIm' and informing mathematica that a certain variable has no imaginary part:
 
<pre>
 
<pre>
<<Algegra`ReIm`
+
<<Algebra`ReIm`
z :/ Im[z] = 0;
+
z /: Im[z] = 0;
 
</pre>
 
</pre>
 
Please note that this uses ''a single equal sign'' rather than the usual two you are accustomed to in Mathematica.  Another option that performs nearly identical functionality is to give the function you're using certain assumptions for solving the variables as reals, for example:
 
Please note that this uses ''a single equal sign'' rather than the usual two you are accustomed to in Mathematica.  Another option that performs nearly identical functionality is to give the function you're using certain assumptions for solving the variables as reals, for example:

Latest revision as of 18:20, 29 January 2007

Working with Complex Numbers

Mathematica has certain issues with complex numbers that make it difficult to use under certain circumstances, to entirely turn off complex number support you should include the 'RealOnly' package:

<<Miscellaneous`RealOnly`

However, this does not solve all problems with complex numbers since you may need to have Mathematica perform operations with complex numbers but not use them in certain variables. You can achieve this by including the package 'ReIm' and informing mathematica that a certain variable has no imaginary part:

<<Algebra`ReIm`
z /: Im[z] = 0;

Please note that this uses a single equal sign rather than the usual two you are accustomed to in Mathematica. Another option that performs nearly identical functionality is to give the function you're using certain assumptions for solving the variables as reals, for example:

Simplify[difficultExpression,Assumptions -> {Im[x] == 0}]

Please note that the Assumptions tag only works for the functions Integrate, Refine, and Simplify. If you are starting with something else you can take the resulting "difficultExpression" and use it in Simplify in order to use the Assumptions tag.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox