![]() |
![]() |
|||
|
One of the nicest (and sometimes most frustrating!) features of Mathematica
is that it is exact. In an attempt to be exact, Mathematica will generally
not give results on calculations that it doesn't know exactly how to handle.
If you asked it for a+b without defining a
or b, you would get back a+b.
If you open an notebook and type Pi you will
get 3/4 on the other hand, is different. It is a rational expression, and it has a terminating decimal representation: 0.75 is identically equal to 3/4. These two representations of the same number can be used interchangably with no loss of accuracy in the calculation. The preference of the mathematician or the purpose of the calculation usually dictates which form we use, but it doesn't matter if we switch between the two. If you ask Mathematica what 3/4 is, it makes the assumption that you want to work with rational numbers, and will return 3/4.
If you really want it to tell you that 3/4 is 0.75, you will need to ask for N[3/4], which will give you the numerical value of 3/4. In this case it can tell us that it is 0.75.
Alternatively, you can tell Mathematica that it is ok to use Real numbers by entering 3./4. and thereby obtain an answer of 0.75. Mathematica will assume that if you enter 3, it can only use Integers. If you enter 3/4, it can use Integers or Rational numbers. If you enter 3., you tell Mathematica to use the Real representation of 3. In the case of 1/3, however, there is not an exact numerical representation of the number. Asking Mathematica for N[1/3] gives:
As you can see here, Mathematica shows six decimal places. By default Mathematica works to sixteen decimal precision, but shows the first six. If you want Mathematica to work harder, you can give N a second argument telling it how precise you would like the answer to be. In those cases it will show you all of the decimal places you ask it to work with, so if we wanted the first twenty decimal places of 1/3, we could ask Mathematica for N[1/3,20]. However, be aware that Mathematica can not verify for itself how accurate the answer is. If you want to make sure you get the first n digits of a complex calculation correct, ask Mathematica to work with more precision than you need. By asking it to make a calculation and then asking it to work harder to do the same calculation, you can judge how accurate the calculation is. If the decimal places that you are interested in do not change then you can probably accept that answer.
|
||||
| Tutorial
Home Table of Contents About this Site |
||||
| Previous: Naming conventions and Mathematica's Unifying Idea | Next: HELP! |
Last updated:5/1/02
|
||