Mercurial > emacs
comparison man/calc.texi @ 90066:fb79180b618d
Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-78
Merge from emacs--cvs-trunk--0
Patches applied:
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-719
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-732
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-733
Update from CVS: man/calc.texi: Fix some TeX definitions.
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-734
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-75
Merge from emacs--cvs-trunk--0
* miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-76
- miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-77
Update from CVS
author | Miles Bader <miles@gnu.org> |
---|---|
date | Tue, 14 Dec 2004 07:34:55 +0000 |
parents | f2ebccfa87d4 061e79e10789 |
children | eac554634bfa |
comparison
equal
deleted
inserted
replaced
90065:c26eb15cd14a | 90066:fb79180b618d |
---|---|
11 @c @texline foo | 11 @c @texline foo |
12 @c `foo' will appear only in TeX output | 12 @c `foo' will appear only in TeX output |
13 @c @infoline foo | 13 @c @infoline foo |
14 @c `foo' will appear only in non-TeX output | 14 @c `foo' will appear only in non-TeX output |
15 | 15 |
16 @c In TeX output, @tmath{expr} will typeset expr in math mode. | 16 @c @expr{expr} will typeset an expression; |
17 @c In any output, @expr{expr} will typeset an expression; | |
18 @c $x$ in TeX, @samp{x} otherwise. | 17 @c $x$ in TeX, @samp{x} otherwise. |
19 | 18 |
20 @iftex | 19 @iftex |
21 @macro texline{stuff} | 20 @macro texline{stuff} |
22 \stuff\ | 21 \stuff\ |
23 @end macro | 22 @end macro |
24 @macro tmath{stuff} | 23 @alias infoline=comment |
25 @tex | 24 @tex |
26 $\stuff\$ | 25 \gdef\exprsetup{\tex \let\t\ttfont \turnoffactive} |
26 \gdef\expr{\exprsetup$\exprfinish} | |
27 \gdef\exprfinish#1{#1$\endgroup} | |
27 @end tex | 28 @end tex |
28 @end macro | 29 @alias mathit=expr |
29 @alias infoline=comment | |
30 @c @alias expr=math | |
31 @tex | |
32 \gdef\expr#1{\tex | |
33 \let\t\ttfont | |
34 \turnoffactive | |
35 $#1$ | |
36 \endgroup} | |
37 @end tex | |
38 @macro cpi{} | 30 @macro cpi{} |
39 @math{@pi{}} | 31 @math{@pi{}} |
40 @end macro | 32 @end macro |
41 @macro cpiover{den} | 33 @macro cpiover{den} |
42 @math{@pi/\den\} | 34 @math{@pi/\den\} |
47 @alias texline=comment | 39 @alias texline=comment |
48 @macro infoline{stuff} | 40 @macro infoline{stuff} |
49 \stuff\ | 41 \stuff\ |
50 @end macro | 42 @end macro |
51 @alias expr=samp | 43 @alias expr=samp |
44 @alias mathit=i | |
52 @macro cpi{} | 45 @macro cpi{} |
53 @expr{pi} | 46 @expr{pi} |
54 @end macro | 47 @end macro |
55 @macro cpiover{den} | 48 @macro cpiover{den} |
56 @expr{pi/\den\} | 49 @expr{pi/\den\} |
622 @strong{RPN calculation.} In RPN, you type the input number(s) first, | 615 @strong{RPN calculation.} In RPN, you type the input number(s) first, |
623 then the command to operate on the numbers. | 616 then the command to operate on the numbers. |
624 | 617 |
625 @noindent | 618 @noindent |
626 Type @kbd{2 @key{RET} 3 + Q} to compute | 619 Type @kbd{2 @key{RET} 3 + Q} to compute |
627 @texline @tmath{\sqrt{2+3} = 2.2360679775}. | 620 @texline @math{\sqrt{2+3} = 2.2360679775}. |
628 @infoline the square root of 2+3, which is 2.2360679775. | 621 @infoline the square root of 2+3, which is 2.2360679775. |
629 | 622 |
630 @noindent | 623 @noindent |
631 Type @kbd{P 2 ^} to compute | 624 Type @kbd{P 2 ^} to compute |
632 @texline @tmath{\pi^2 = 9.86960440109}. | 625 @texline @math{\pi^2 = 9.86960440109}. |
633 @infoline the value of `pi' squared, 9.86960440109. | 626 @infoline the value of `pi' squared, 9.86960440109. |
634 | 627 |
635 @noindent | 628 @noindent |
636 Type @key{TAB} to exchange the order of these two results. | 629 Type @key{TAB} to exchange the order of these two results. |
637 | 630 |
646 conventional ``algebraic'' notation. To enter an algebraic formula, | 639 conventional ``algebraic'' notation. To enter an algebraic formula, |
647 use the apostrophe key. | 640 use the apostrophe key. |
648 | 641 |
649 @noindent | 642 @noindent |
650 Type @kbd{' sqrt(2+3) @key{RET}} to compute | 643 Type @kbd{' sqrt(2+3) @key{RET}} to compute |
651 @texline @tmath{\sqrt{2+3}}. | 644 @texline @math{\sqrt{2+3}}. |
652 @infoline the square root of 2+3. | 645 @infoline the square root of 2+3. |
653 | 646 |
654 @noindent | 647 @noindent |
655 Type @kbd{' pi^2 @key{RET}} to enter | 648 Type @kbd{' pi^2 @key{RET}} to enter |
656 @texline @tmath{\pi^2}. | 649 @texline @math{\pi^2}. |
657 @infoline `pi' squared. | 650 @infoline `pi' squared. |
658 To evaluate this symbolic formula as a number, type @kbd{=}. | 651 To evaluate this symbolic formula as a number, type @kbd{=}. |
659 | 652 |
660 @noindent | 653 @noindent |
661 Type @kbd{' arcsinh($ - $$) @key{RET}} to subtract the second-most-recent | 654 Type @kbd{' arcsinh($ - $$) @key{RET}} to subtract the second-most-recent |
711 the upper-leftmost @samp{1} and set the mark, then move to just after | 704 the upper-leftmost @samp{1} and set the mark, then move to just after |
712 the lower-right @samp{8} and press @kbd{M-# r}. | 705 the lower-right @samp{8} and press @kbd{M-# r}. |
713 | 706 |
714 @noindent | 707 @noindent |
715 Type @kbd{v t} to transpose this | 708 Type @kbd{v t} to transpose this |
716 @texline @tmath{3\times2} | 709 @texline @math{3\times2} |
717 @infoline 3x2 | 710 @infoline 3x2 |
718 matrix into a | 711 matrix into a |
719 @texline @tmath{2\times3} | 712 @texline @math{2\times3} |
720 @infoline 2x3 | 713 @infoline 2x3 |
721 matrix. Type @w{@kbd{v u}} to unpack the rows into two separate | 714 matrix. Type @w{@kbd{v u}} to unpack the rows into two separate |
722 vectors. Now type @w{@kbd{V R + @key{TAB} V R +}} to compute the sums | 715 vectors. Now type @w{@kbd{V R + @key{TAB} V R +}} to compute the sums |
723 of the two original columns. (There is also a special | 716 of the two original columns. (There is also a special |
724 grab-and-sum-columns command, @kbd{M-# :}.) | 717 grab-and-sum-columns command, @kbd{M-# :}.) |
823 commands like @kbd{M-x calc} (for the standard user interface) or | 816 commands like @kbd{M-x calc} (for the standard user interface) or |
824 @w{@kbd{M-x calc-keypad}} (for Keypad Mode). First type @kbd{M-x} | 817 @w{@kbd{M-x calc-keypad}} (for Keypad Mode). First type @kbd{M-x} |
825 (that's Meta with the letter @kbd{x}), then, at the prompt, | 818 (that's Meta with the letter @kbd{x}), then, at the prompt, |
826 type the full command (like @kbd{calc-keypad}) and press Return. | 819 type the full command (like @kbd{calc-keypad}) and press Return. |
827 | 820 |
828 If you type @kbd{M-x calc} and Emacs still doesn't recognize the | |
829 command (it will say @samp{[No match]} when you try to press | |
830 @key{RET}), then Calc has not been properly installed. | |
831 | |
832 The same commands (like @kbd{M-# c} or @kbd{M-# M-#}) that start | 821 The same commands (like @kbd{M-# c} or @kbd{M-# M-#}) that start |
833 the Calculator also turn it off if it is already on. | 822 the Calculator also turn it off if it is already on. |
834 | 823 |
835 @node The Standard Interface, Quick Mode Overview, Starting Calc, Using Calc | 824 @node The Standard Interface, Quick Mode Overview, Starting Calc, Using Calc |
836 @subsection The Standard Calc Interface | 825 @subsection The Standard Calc Interface |
869 a printer, the trail corresponds to the paper tape that records what | 858 a printer, the trail corresponds to the paper tape that records what |
870 you do. | 859 you do. |
871 | 860 |
872 In this case, the trail shows that four numbers (17.3, 3, 2, and 4) | 861 In this case, the trail shows that four numbers (17.3, 3, 2, and 4) |
873 were first entered into the Calculator, then the 2 and 4 were | 862 were first entered into the Calculator, then the 2 and 4 were |
874 multiplied to get 8, then the 3 and 8 were subtracted to get @i{-5}. | 863 multiplied to get 8, then the 3 and 8 were subtracted to get @mathit{-5}. |
875 (The @samp{>} symbol shows that this was the most recent calculation.) | 864 (The @samp{>} symbol shows that this was the most recent calculation.) |
876 The net result is the two numbers 17.3 and @i{-5} sitting on the stack. | 865 The net result is the two numbers 17.3 and @mathit{-5} sitting on the stack. |
877 | 866 |
878 Most Calculator commands deal explicitly with the stack only, but | 867 Most Calculator commands deal explicitly with the stack only, but |
879 there is a set of commands that allow you to search back through | 868 there is a set of commands that allow you to search back through |
880 the trail and retrieve any previous result. | 869 the trail and retrieve any previous result. |
881 | 870 |
932 full complexity of the stack and trail. To use it, type @kbd{M-# q} | 921 full complexity of the stack and trail. To use it, type @kbd{M-# q} |
933 (@code{quick-calc}) in any regular editing buffer. | 922 (@code{quick-calc}) in any regular editing buffer. |
934 | 923 |
935 Quick Mode is very simple: It prompts you to type any formula in | 924 Quick Mode is very simple: It prompts you to type any formula in |
936 standard algebraic notation (like @samp{4 - 2/3}) and then displays | 925 standard algebraic notation (like @samp{4 - 2/3}) and then displays |
937 the result at the bottom of the Emacs screen (@i{3.33333333333} | 926 the result at the bottom of the Emacs screen (@mathit{3.33333333333} |
938 in this case). You are then back in the same editing buffer you | 927 in this case). You are then back in the same editing buffer you |
939 were in before, ready to continue editing or to type @kbd{M-# q} | 928 were in before, ready to continue editing or to type @kbd{M-# q} |
940 again to do another quick calculation. The result of the calculation | 929 again to do another quick calculation. The result of the calculation |
941 will also be in the Emacs ``kill ring'' so that a @kbd{C-y} command | 930 will also be in the Emacs ``kill ring'' so that a @kbd{C-y} command |
942 at this point will yank the result into your editing buffer. | 931 at this point will yank the result into your editing buffer. |
952 | 941 |
953 @noindent | 942 @noindent |
954 @dfn{Keypad Mode} is a mouse-based interface to the Calculator. | 943 @dfn{Keypad Mode} is a mouse-based interface to the Calculator. |
955 It is designed for use with terminals that support a mouse. If you | 944 It is designed for use with terminals that support a mouse. If you |
956 don't have a mouse, you will have to operate keypad mode with your | 945 don't have a mouse, you will have to operate keypad mode with your |
957 arrow keys (which is probably more trouble than it's worth). Keypad | 946 arrow keys (which is probably more trouble than it's worth). |
958 mode is currently not supported under Emacs 19. | |
959 | 947 |
960 Type @kbd{M-# k} to turn Keypad Mode on or off. Once again you | 948 Type @kbd{M-# k} to turn Keypad Mode on or off. Once again you |
961 get two new windows, this time on the righthand side of the screen | 949 get two new windows, this time on the righthand side of the screen |
962 instead of at the bottom. The upper window is the familiar Calc | 950 instead of at the bottom. The upper window is the familiar Calc |
963 Stack; the lower window is a picture of a typical calculator keypad. | 951 Stack; the lower window is a picture of a typical calculator keypad. |
1346 | 1334 |
1347 @noindent | 1335 @noindent |
1348 Calc was originally started as a two-week project to occupy a lull | 1336 Calc was originally started as a two-week project to occupy a lull |
1349 in the author's schedule. Basically, a friend asked if I remembered | 1337 in the author's schedule. Basically, a friend asked if I remembered |
1350 the value of | 1338 the value of |
1351 @texline @tmath{2^{32}}. | 1339 @texline @math{2^{32}}. |
1352 @infoline @expr{2^32}. | 1340 @infoline @expr{2^32}. |
1353 I didn't offhand, but I said, ``that's easy, just call up an | 1341 I didn't offhand, but I said, ``that's easy, just call up an |
1354 @code{xcalc}.'' @code{Xcalc} duly reported that the answer to our | 1342 @code{xcalc}.'' @code{Xcalc} duly reported that the answer to our |
1355 question was @samp{4.294967e+09}---with no way to see the full ten | 1343 question was @samp{4.294967e+09}---with no way to see the full ten |
1356 digits even though we knew they were there in the program's memory! I | 1344 digits even though we knew they were there in the program's memory! I |
1668 @key{RET} 3 @key{RET} 4 + * -} compute? (@samp{*} is the symbol for | 1656 @key{RET} 3 @key{RET} 4 + * -} compute? (@samp{*} is the symbol for |
1669 multiplication.) Figure it out by hand, then try it with Calc to see | 1657 multiplication.) Figure it out by hand, then try it with Calc to see |
1670 if you're right. @xref{RPN Answer 1, 1}. (@bullet{}) | 1658 if you're right. @xref{RPN Answer 1, 1}. (@bullet{}) |
1671 | 1659 |
1672 (@bullet{}) @strong{Exercise 2.} Compute | 1660 (@bullet{}) @strong{Exercise 2.} Compute |
1673 @texline @tmath{(2\times4) + (7\times9.4) + {5\over4}} | 1661 @texline @math{(2\times4) + (7\times9.4) + {5\over4}} |
1674 @infoline @expr{2*4 + 7*9.5 + 5/4} | 1662 @infoline @expr{2*4 + 7*9.5 + 5/4} |
1675 using the stack. @xref{RPN Answer 2, 2}. (@bullet{}) | 1663 using the stack. @xref{RPN Answer 2, 2}. (@bullet{}) |
1676 | 1664 |
1677 The @key{DEL} key is called Backspace on some keyboards. It is | 1665 The @key{DEL} key is called Backspace on some keyboards. It is |
1678 whatever key you would use to correct a simple typing error when | 1666 whatever key you would use to correct a simple typing error when |
2003 $$ 2 + { 3 \times 4 \times 5 \over 6 \times 7^8 } - 9 $$ | 1991 $$ 2 + { 3 \times 4 \times 5 \over 6 \times 7^8 } - 9 $$ |
2004 \afterdisplay | 1992 \afterdisplay |
2005 @end tex | 1993 @end tex |
2006 | 1994 |
2007 @noindent | 1995 @noindent |
2008 The result of this expression will be the number @i{-6.99999826533}. | 1996 The result of this expression will be the number @mathit{-6.99999826533}. |
2009 | 1997 |
2010 Calc's order of evaluation is the same as for most computer languages, | 1998 Calc's order of evaluation is the same as for most computer languages, |
2011 except that @samp{*} binds more strongly than @samp{/}, as the above | 1999 except that @samp{*} binds more strongly than @samp{/}, as the above |
2012 example shows. As in normal mathematical notation, the @samp{*} symbol | 2000 example shows. As in normal mathematical notation, the @samp{*} symbol |
2013 can often be omitted: @samp{2 a} is the same as @samp{2*a}. | 2001 can often be omitted: @samp{2 a} is the same as @samp{2*a}. |
2014 | 2002 |
2015 Operators at the same level are evaluated from left to right, except | 2003 Operators at the same level are evaluated from left to right, except |
2016 that @samp{^} is evaluated from right to left. Thus, @samp{2-3-4} is | 2004 that @samp{^} is evaluated from right to left. Thus, @samp{2-3-4} is |
2017 equivalent to @samp{(2-3)-4} or @i{-5}, whereas @samp{2^3^4} is equivalent | 2005 equivalent to @samp{(2-3)-4} or @mathit{-5}, whereas @samp{2^3^4} is equivalent |
2018 to @samp{2^(3^4)} (a very large integer; try it!). | 2006 to @samp{2^(3^4)} (a very large integer; try it!). |
2019 | 2007 |
2020 If you tire of typing the apostrophe all the time, there is an | 2008 If you tire of typing the apostrophe all the time, there is an |
2021 ``algebraic mode'' you can select in which Calc automatically senses | 2009 ``algebraic mode'' you can select in which Calc automatically senses |
2022 when you are about to type an algebraic expression. To enter this | 2010 when you are about to type an algebraic expression. To enter this |
2082 intermediate results of a calculation as you go along. You can | 2070 intermediate results of a calculation as you go along. You can |
2083 accomplish this in Calc by performing your calculation as a series | 2071 accomplish this in Calc by performing your calculation as a series |
2084 of algebraic entries, using the @kbd{$} sign to tie them together. | 2072 of algebraic entries, using the @kbd{$} sign to tie them together. |
2085 In an algebraic formula, @kbd{$} represents the number on the top | 2073 In an algebraic formula, @kbd{$} represents the number on the top |
2086 of the stack. Here, we perform the calculation | 2074 of the stack. Here, we perform the calculation |
2087 @texline @tmath{\sqrt{2\times4+1}}, | 2075 @texline @math{\sqrt{2\times4+1}}, |
2088 @infoline @expr{sqrt(2*4+1)}, | 2076 @infoline @expr{sqrt(2*4+1)}, |
2089 which on a traditional calculator would be done by pressing | 2077 which on a traditional calculator would be done by pressing |
2090 @kbd{2 * 4 + 1 =} and then the square-root key. | 2078 @kbd{2 * 4 + 1 =} and then the square-root key. |
2091 | 2079 |
2092 @smallexample | 2080 @smallexample |
2744 @end smallexample | 2732 @end smallexample |
2745 | 2733 |
2746 @noindent | 2734 @noindent |
2747 The shift-@kbd{S} command computes the sine of an angle. The sine | 2735 The shift-@kbd{S} command computes the sine of an angle. The sine |
2748 of 45 degrees is | 2736 of 45 degrees is |
2749 @texline @tmath{\sqrt{2}/2}; | 2737 @texline @math{\sqrt{2}/2}; |
2750 @infoline @expr{sqrt(2)/2}; | 2738 @infoline @expr{sqrt(2)/2}; |
2751 squaring this yields @expr{2/4 = 0.5}. However, there has been a slight | 2739 squaring this yields @expr{2/4 = 0.5}. However, there has been a slight |
2752 roundoff error because the representation of | 2740 roundoff error because the representation of |
2753 @texline @tmath{\sqrt{2}/2} | 2741 @texline @math{\sqrt{2}/2} |
2754 @infoline @expr{sqrt(2)/2} | 2742 @infoline @expr{sqrt(2)/2} |
2755 wasn't exact. The @kbd{c 1} command is a handy way to clean up numbers | 2743 wasn't exact. The @kbd{c 1} command is a handy way to clean up numbers |
2756 in this case; it temporarily reduces the precision by one digit while it | 2744 in this case; it temporarily reduces the precision by one digit while it |
2757 re-rounds the number on the top of the stack. | 2745 re-rounds the number on the top of the stack. |
2758 | 2746 |
2789 @end group | 2777 @end group |
2790 @end smallexample | 2778 @end smallexample |
2791 | 2779 |
2792 @noindent | 2780 @noindent |
2793 Here we compute the Inverse Sine of | 2781 Here we compute the Inverse Sine of |
2794 @texline @tmath{\sqrt{0.5}}, | 2782 @texline @math{\sqrt{0.5}}, |
2795 @infoline @expr{sqrt(0.5)}, | 2783 @infoline @expr{sqrt(0.5)}, |
2796 first in radians, then in degrees. | 2784 first in radians, then in degrees. |
2797 | 2785 |
2798 Use @kbd{c d} and @kbd{c r} to convert a number from radians to degrees | 2786 Use @kbd{c d} and @kbd{c r} to convert a number from radians to degrees |
2799 and vice-versa. | 2787 and vice-versa. |
2977 logarithm). These can be modified by the @kbd{I} (inverse) and | 2965 logarithm). These can be modified by the @kbd{I} (inverse) and |
2978 @kbd{H} (hyperbolic) prefix keys. | 2966 @kbd{H} (hyperbolic) prefix keys. |
2979 | 2967 |
2980 Let's compute the sine and cosine of an angle, and verify the | 2968 Let's compute the sine and cosine of an angle, and verify the |
2981 identity | 2969 identity |
2982 @texline @tmath{\sin^2x + \cos^2x = 1}. | 2970 @texline @math{\sin^2x + \cos^2x = 1}. |
2983 @infoline @expr{sin(x)^2 + cos(x)^2 = 1}. | 2971 @infoline @expr{sin(x)^2 + cos(x)^2 = 1}. |
2984 We'll arbitrarily pick @i{-64} degrees as a good value for @expr{x}. | 2972 We'll arbitrarily pick @mathit{-64} degrees as a good value for @expr{x}. |
2985 With the angular mode set to degrees (type @w{@kbd{m d}}), do: | 2973 With the angular mode set to degrees (type @w{@kbd{m d}}), do: |
2986 | 2974 |
2987 @smallexample | 2975 @smallexample |
2988 @group | 2976 @group |
2989 2: -64 2: -64 2: -0.89879 2: -0.89879 1: 1. | 2977 2: -64 2: -64 2: -0.89879 2: -0.89879 1: 1. |
3000 | 2988 |
3001 Remember, @kbd{f h} is the @code{calc-hypot}, or square-root of sum | 2989 Remember, @kbd{f h} is the @code{calc-hypot}, or square-root of sum |
3002 of squares, command. | 2990 of squares, command. |
3003 | 2991 |
3004 Another identity is | 2992 Another identity is |
3005 @texline @tmath{\displaystyle\tan x = {\sin x \over \cos x}}. | 2993 @texline @math{\displaystyle\tan x = {\sin x \over \cos x}}. |
3006 @infoline @expr{tan(x) = sin(x) / cos(x)}. | 2994 @infoline @expr{tan(x) = sin(x) / cos(x)}. |
3007 @smallexample | 2995 @smallexample |
3008 @group | 2996 @group |
3009 | 2997 |
3010 2: -0.89879 1: -2.0503 1: -64. | 2998 2: -0.89879 1: -2.0503 1: -64. |
3015 @end group | 3003 @end group |
3016 @end smallexample | 3004 @end smallexample |
3017 | 3005 |
3018 A physical interpretation of this calculation is that if you move | 3006 A physical interpretation of this calculation is that if you move |
3019 @expr{0.89879} units downward and @expr{0.43837} units to the right, | 3007 @expr{0.89879} units downward and @expr{0.43837} units to the right, |
3020 your direction of motion is @i{-64} degrees from horizontal. Suppose | 3008 your direction of motion is @mathit{-64} degrees from horizontal. Suppose |
3021 we move in the opposite direction, up and to the left: | 3009 we move in the opposite direction, up and to the left: |
3022 | 3010 |
3023 @smallexample | 3011 @smallexample |
3024 @group | 3012 @group |
3025 2: -0.89879 2: 0.89879 1: -2.0503 1: -64. | 3013 2: -0.89879 2: 0.89879 1: -2.0503 1: -64. |
3063 the top two stack elements right after the @kbd{U U}, then a pair of | 3051 the top two stack elements right after the @kbd{U U}, then a pair of |
3064 @kbd{M-@key{TAB}} commands to cycle the 116 up around the duplicates. | 3052 @kbd{M-@key{TAB}} commands to cycle the 116 up around the duplicates. |
3065 | 3053 |
3066 A similar identity is supposed to hold for hyperbolic sines and cosines, | 3054 A similar identity is supposed to hold for hyperbolic sines and cosines, |
3067 except that it is the @emph{difference} | 3055 except that it is the @emph{difference} |
3068 @texline @tmath{\cosh^2x - \sinh^2x} | 3056 @texline @math{\cosh^2x - \sinh^2x} |
3069 @infoline @expr{cosh(x)^2 - sinh(x)^2} | 3057 @infoline @expr{cosh(x)^2 - sinh(x)^2} |
3070 that always equals one. Let's try to verify this identity. | 3058 that always equals one. Let's try to verify this identity. |
3071 | 3059 |
3072 @smallexample | 3060 @smallexample |
3073 @group | 3061 @group |
3170 exact integer, you get an exact integer result (158 digits long | 3158 exact integer, you get an exact integer result (158 digits long |
3171 in this case). | 3159 in this case). |
3172 | 3160 |
3173 If you take the factorial of a non-integer, Calc uses a generalized | 3161 If you take the factorial of a non-integer, Calc uses a generalized |
3174 factorial function defined in terms of Euler's Gamma function | 3162 factorial function defined in terms of Euler's Gamma function |
3175 @texline @tmath{\Gamma(n)} | 3163 @texline @math{\Gamma(n)} |
3176 @infoline @expr{gamma(n)} | 3164 @infoline @expr{gamma(n)} |
3177 (which is itself available as the @kbd{f g} command). | 3165 (which is itself available as the @kbd{f g} command). |
3178 | 3166 |
3179 @smallexample | 3167 @smallexample |
3180 @group | 3168 @group |
3187 @end group | 3175 @end group |
3188 @end smallexample | 3176 @end smallexample |
3189 | 3177 |
3190 @noindent | 3178 @noindent |
3191 Here we verify the identity | 3179 Here we verify the identity |
3192 @texline @tmath{n! = \Gamma(n+1)}. | 3180 @texline @math{n! = \Gamma(n+1)}. |
3193 @infoline @expr{@var{n}!@: = gamma(@var{n}+1)}. | 3181 @infoline @expr{@var{n}!@: = gamma(@var{n}+1)}. |
3194 | 3182 |
3195 The binomial coefficient @var{n}-choose-@var{m} | 3183 The binomial coefficient @var{n}-choose-@var{m} |
3196 @texline or @tmath{\displaystyle {n \choose m}} | 3184 @texline or @math{\displaystyle {n \choose m}} |
3197 is defined by | 3185 is defined by |
3198 @texline @tmath{\displaystyle {n! \over m! \, (n-m)!}} | 3186 @texline @math{\displaystyle {n! \over m! \, (n-m)!}} |
3199 @infoline @expr{n!@: / m!@: (n-m)!} | 3187 @infoline @expr{n!@: / m!@: (n-m)!} |
3200 for all reals @expr{n} and @expr{m}. The intermediate results in this | 3188 for all reals @expr{n} and @expr{m}. The intermediate results in this |
3201 formula can become quite large even if the final result is small; the | 3189 formula can become quite large even if the final result is small; the |
3202 @kbd{k c} command computes a binomial coefficient in a way that avoids | 3190 @kbd{k c} command computes a binomial coefficient in a way that avoids |
3203 large intermediate values. | 3191 large intermediate values. |
3478 rows in the matrix is different from the number of elements in the | 3466 rows in the matrix is different from the number of elements in the |
3479 vector. | 3467 vector. |
3480 | 3468 |
3481 (@bullet{}) @strong{Exercise 1.} Use @samp{*} to sum along the rows | 3469 (@bullet{}) @strong{Exercise 1.} Use @samp{*} to sum along the rows |
3482 of the above | 3470 of the above |
3483 @texline @tmath{2\times3} | 3471 @texline @math{2\times3} |
3484 @infoline 2x3 | 3472 @infoline 2x3 |
3485 matrix to get @expr{[6, 15]}. Now use @samp{*} to sum along the columns | 3473 matrix to get @expr{[6, 15]}. Now use @samp{*} to sum along the columns |
3486 to get @expr{[5, 7, 9]}. | 3474 to get @expr{[5, 7, 9]}. |
3487 @xref{Matrix Answer 1, 1}. (@bullet{}) | 3475 @xref{Matrix Answer 1, 1}. (@bullet{}) |
3488 | 3476 |
3629 the matrix and vector. If we multiplied in the other order, Calc would | 3617 the matrix and vector. If we multiplied in the other order, Calc would |
3630 assume the vector was a row vector in order to make the dimensions | 3618 assume the vector was a row vector in order to make the dimensions |
3631 come out right, and the answer would be incorrect. If you | 3619 come out right, and the answer would be incorrect. If you |
3632 don't feel safe letting Calc take either interpretation of your | 3620 don't feel safe letting Calc take either interpretation of your |
3633 vectors, use explicit | 3621 vectors, use explicit |
3634 @texline @tmath{N\times1} | 3622 @texline @math{N\times1} |
3635 @infoline Nx1 | 3623 @infoline Nx1 |
3636 or | 3624 or |
3637 @texline @tmath{1\times N} | 3625 @texline @math{1\times N} |
3638 @infoline 1xN | 3626 @infoline 1xN |
3639 matrices instead. In this case, you would enter the original column | 3627 matrices instead. In this case, you would enter the original column |
3640 vector as @samp{[[6], [2], [3]]} or @samp{[6; 2; 3]}. | 3628 vector as @samp{[[6], [2], [3]]} or @samp{[6; 2; 3]}. |
3641 | 3629 |
3642 (@bullet{}) @strong{Exercise 2.} Algebraic entry allows you to make | 3630 (@bullet{}) @strong{Exercise 2.} Algebraic entry allows you to make |
3681 @tex | 3669 @tex |
3682 \turnoffactive | 3670 \turnoffactive |
3683 $A^T A \, X = A^T B$, where $A^T$ is the transpose \samp{trn(A)}. | 3671 $A^T A \, X = A^T B$, where $A^T$ is the transpose \samp{trn(A)}. |
3684 @end tex | 3672 @end tex |
3685 Now | 3673 Now |
3686 @texline @tmath{A^T A} | 3674 @texline @math{A^T A} |
3687 @infoline @expr{trn(A)*A} | 3675 @infoline @expr{trn(A)*A} |
3688 is a square matrix so a solution is possible. It turns out that the | 3676 is a square matrix so a solution is possible. It turns out that the |
3689 @expr{X} vector you compute in this way will be a ``least-squares'' | 3677 @expr{X} vector you compute in this way will be a ``least-squares'' |
3690 solution, which can be regarded as the ``closest'' solution to the set | 3678 solution, which can be regarded as the ``closest'' solution to the set |
3691 of equations. Use Calc to solve the following over-determined | 3679 of equations. Use Calc to solve the following over-determined |
3777 other a plain number.) In the final step, we take the square root | 3765 other a plain number.) In the final step, we take the square root |
3778 of each element. | 3766 of each element. |
3779 | 3767 |
3780 (@bullet{}) @strong{Exercise 1.} Compute a vector of powers of two | 3768 (@bullet{}) @strong{Exercise 1.} Compute a vector of powers of two |
3781 from | 3769 from |
3782 @texline @tmath{2^{-4}} | 3770 @texline @math{2^{-4}} |
3783 @infoline @expr{2^-4} | 3771 @infoline @expr{2^-4} |
3784 to @expr{2^4}. @xref{List Answer 1, 1}. (@bullet{}) | 3772 to @expr{2^4}. @xref{List Answer 1, 1}. (@bullet{}) |
3785 | 3773 |
3786 You can also @dfn{reduce} a binary operator across a vector. | 3774 You can also @dfn{reduce} a binary operator across a vector. |
3787 For example, reducing @samp{*} computes the product of all the | 3775 For example, reducing @samp{*} computes the product of all the |
3981 \afterdisplay | 3969 \afterdisplay |
3982 @end tex | 3970 @end tex |
3983 | 3971 |
3984 @noindent | 3972 @noindent |
3985 where | 3973 where |
3986 @texline @tmath{\sum x} | 3974 @texline @math{\sum x} |
3987 @infoline @expr{sum(x)} | 3975 @infoline @expr{sum(x)} |
3988 represents the sum of all the values of @expr{x}. While there is an | 3976 represents the sum of all the values of @expr{x}. While there is an |
3989 actual @code{sum} function in Calc, it's easier to sum a vector using a | 3977 actual @code{sum} function in Calc, it's easier to sum a vector using a |
3990 simple reduction. First, let's compute the four different sums that | 3978 simple reduction. First, let's compute the four different sums that |
3991 this formula uses. | 3979 this formula uses. |
4086 r 5 r 8 r 3 * - r 7 / t 9 | 4074 r 5 r 8 r 3 * - r 7 / t 9 |
4087 @end group | 4075 @end group |
4088 @end smallexample | 4076 @end smallexample |
4089 | 4077 |
4090 Let's ``plot'' this straight line approximation, | 4078 Let's ``plot'' this straight line approximation, |
4091 @texline @tmath{y \approx m x + b}, | 4079 @texline @math{y \approx m x + b}, |
4092 @infoline @expr{m x + b}, | 4080 @infoline @expr{m x + b}, |
4093 and compare it with the original data. | 4081 and compare it with the original data. |
4094 | 4082 |
4095 @smallexample | 4083 @smallexample |
4096 @group | 4084 @group |
4339 @xref{List Answer 7, 7}. (@bullet{}) | 4327 @xref{List Answer 7, 7}. (@bullet{}) |
4340 | 4328 |
4341 @cindex Maximizing a function over a list of values | 4329 @cindex Maximizing a function over a list of values |
4342 @c [fix-ref Numerical Solutions] | 4330 @c [fix-ref Numerical Solutions] |
4343 (@bullet{}) @strong{Exercise 8.} Compute a list of values of Bessel's | 4331 (@bullet{}) @strong{Exercise 8.} Compute a list of values of Bessel's |
4344 @texline @tmath{J_1(x)} | 4332 @texline @math{J_1(x)} |
4345 @infoline @expr{J1} | 4333 @infoline @expr{J1} |
4346 function @samp{besJ(1,x)} for @expr{x} from 0 to 5 in steps of 0.25. | 4334 function @samp{besJ(1,x)} for @expr{x} from 0 to 5 in steps of 0.25. |
4347 Find the value of @expr{x} (from among the above set of values) for | 4335 Find the value of @expr{x} (from among the above set of values) for |
4348 which @samp{besJ(1,x)} is a maximum. Use an ``automatic'' method, | 4336 which @samp{besJ(1,x)} is a maximum. Use an ``automatic'' method, |
4349 i.e., just reading along the list by hand to find the largest value | 4337 i.e., just reading along the list by hand to find the largest value |
4351 of thing automatically; @pxref{Numerical Solutions}.) | 4339 of thing automatically; @pxref{Numerical Solutions}.) |
4352 @xref{List Answer 8, 8}. (@bullet{}) | 4340 @xref{List Answer 8, 8}. (@bullet{}) |
4353 | 4341 |
4354 @cindex Digits, vectors of | 4342 @cindex Digits, vectors of |
4355 (@bullet{}) @strong{Exercise 9.} You are given an integer in the range | 4343 (@bullet{}) @strong{Exercise 9.} You are given an integer in the range |
4356 @texline @tmath{0 \le N < 10^m} | 4344 @texline @math{0 \le N < 10^m} |
4357 @infoline @expr{0 <= N < 10^m} | 4345 @infoline @expr{0 <= N < 10^m} |
4358 for @expr{m=12} (i.e., an integer of less than | 4346 for @expr{m=12} (i.e., an integer of less than |
4359 twelve digits). Convert this integer into a vector of @expr{m} | 4347 twelve digits). Convert this integer into a vector of @expr{m} |
4360 digits, each in the range from 0 to 9. In vector-of-digits notation, | 4348 digits, each in the range from 0 to 9. In vector-of-digits notation, |
4361 add one to this integer to produce a vector of @expr{m+1} digits | 4349 add one to this integer to produce a vector of @expr{m+1} digits |
4367 @kbd{V R a =} to test if all numbers in a list were equal. What | 4355 @kbd{V R a =} to test if all numbers in a list were equal. What |
4368 happened? How would you do this test? @xref{List Answer 10, 10}. (@bullet{}) | 4356 happened? How would you do this test? @xref{List Answer 10, 10}. (@bullet{}) |
4369 | 4357 |
4370 (@bullet{}) @strong{Exercise 11.} The area of a circle of radius one | 4358 (@bullet{}) @strong{Exercise 11.} The area of a circle of radius one |
4371 is @cpi{}. The area of the | 4359 is @cpi{}. The area of the |
4372 @texline @tmath{2\times2} | 4360 @texline @math{2\times2} |
4373 @infoline 2x2 | 4361 @infoline 2x2 |
4374 square that encloses that circle is 4. So if we throw @var{n} darts at | 4362 square that encloses that circle is 4. So if we throw @var{n} darts at |
4375 random points in the square, about @cpiover{4} of them will land inside | 4363 random points in the square, about @cpiover{4} of them will land inside |
4376 the circle. This gives us an entertaining way to estimate the value of | 4364 the circle. This gives us an entertaining way to estimate the value of |
4377 @cpi{}. The @w{@kbd{k r}} | 4365 @cpi{}. The @w{@kbd{k r}} |
4378 command picks a random number between zero and the value on the stack. | 4366 command picks a random number between zero and the value on the stack. |
4379 We could get a random floating-point number between @i{-1} and 1 by typing | 4367 We could get a random floating-point number between @mathit{-1} and 1 by typing |
4380 @w{@kbd{2.0 k r 1 -}}. Build a vector of 100 random @expr{(x,y)} points in | 4368 @w{@kbd{2.0 k r 1 -}}. Build a vector of 100 random @expr{(x,y)} points in |
4381 this square, then use vector mapping and reduction to count how many | 4369 this square, then use vector mapping and reduction to count how many |
4382 points lie inside the unit circle. Hint: Use the @kbd{v b} command. | 4370 points lie inside the unit circle. Hint: Use the @kbd{v b} command. |
4383 @xref{List Answer 11, 11}. (@bullet{}) | 4371 @xref{List Answer 11, 11}. (@bullet{}) |
4384 | 4372 |
4386 (@bullet{}) @strong{Exercise 12.} The @dfn{matchstick problem} provides | 4374 (@bullet{}) @strong{Exercise 12.} The @dfn{matchstick problem} provides |
4387 another way to calculate @cpi{}. Say you have an infinite field | 4375 another way to calculate @cpi{}. Say you have an infinite field |
4388 of vertical lines with a spacing of one inch. Toss a one-inch matchstick | 4376 of vertical lines with a spacing of one inch. Toss a one-inch matchstick |
4389 onto the field. The probability that the matchstick will land crossing | 4377 onto the field. The probability that the matchstick will land crossing |
4390 a line turns out to be | 4378 a line turns out to be |
4391 @texline @tmath{2/\pi}. | 4379 @texline @math{2/\pi}. |
4392 @infoline @expr{2/pi}. | 4380 @infoline @expr{2/pi}. |
4393 Toss 100 matchsticks to estimate @cpi{}. (If you want still more fun, | 4381 Toss 100 matchsticks to estimate @cpi{}. (If you want still more fun, |
4394 the probability that the GCD (@w{@kbd{k g}}) of two large integers is | 4382 the probability that the GCD (@w{@kbd{k g}}) of two large integers is |
4395 one turns out to be | 4383 one turns out to be |
4396 @texline @tmath{6/\pi^2}. | 4384 @texline @math{6/\pi^2}. |
4397 @infoline @expr{6/pi^2}. | 4385 @infoline @expr{6/pi^2}. |
4398 That provides yet another way to estimate @cpi{}.) | 4386 That provides yet another way to estimate @cpi{}.) |
4399 @xref{List Answer 12, 12}. (@bullet{}) | 4387 @xref{List Answer 12, 12}. (@bullet{}) |
4400 | 4388 |
4401 (@bullet{}) @strong{Exercise 13.} An algebraic entry of a string in | 4389 (@bullet{}) @strong{Exercise 13.} An algebraic entry of a string in |
4421 commands do nested function evaluations. @kbd{H V U} takes a starting | 4409 commands do nested function evaluations. @kbd{H V U} takes a starting |
4422 value and a number of steps @var{n} from the stack; it then applies the | 4410 value and a number of steps @var{n} from the stack; it then applies the |
4423 function you give to the starting value 0, 1, 2, up to @var{n} times | 4411 function you give to the starting value 0, 1, 2, up to @var{n} times |
4424 and returns a vector of the results. Use this command to create a | 4412 and returns a vector of the results. Use this command to create a |
4425 ``random walk'' of 50 steps. Start with the two-dimensional point | 4413 ``random walk'' of 50 steps. Start with the two-dimensional point |
4426 @expr{(0,0)}; then take one step a random distance between @i{-1} and 1 | 4414 @expr{(0,0)}; then take one step a random distance between @mathit{-1} and 1 |
4427 in both @expr{x} and @expr{y}; then take another step, and so on. Use the | 4415 in both @expr{x} and @expr{y}; then take another step, and so on. Use the |
4428 @kbd{g f} command to display this random walk. Now modify your random | 4416 @kbd{g f} command to display this random walk. Now modify your random |
4429 walk to walk a unit distance, but in a random direction, at each step. | 4417 walk to walk a unit distance, but in a random direction, at each step. |
4430 (Hint: The @code{sincos} function returns a vector of the cosine and | 4418 (Hint: The @code{sincos} function returns a vector of the cosine and |
4431 sine of an angle.) @xref{List Answer 14, 14}. (@bullet{}) | 4419 sine of an angle.) @xref{List Answer 14, 14}. (@bullet{}) |
4500 9 n Q c p 2 * Q | 4488 9 n Q c p 2 * Q |
4501 @end group | 4489 @end group |
4502 @end smallexample | 4490 @end smallexample |
4503 | 4491 |
4504 @noindent | 4492 @noindent |
4505 The square root of @i{-9} is by default rendered in rectangular form | 4493 The square root of @mathit{-9} is by default rendered in rectangular form |
4506 (@w{@expr{0 + 3i}}), but we can convert it to polar form (3 with a | 4494 (@w{@expr{0 + 3i}}), but we can convert it to polar form (3 with a |
4507 phase angle of 90 degrees). All the usual arithmetic and scientific | 4495 phase angle of 90 degrees). All the usual arithmetic and scientific |
4508 operations are defined on both types of complex numbers. | 4496 operations are defined on both types of complex numbers. |
4509 | 4497 |
4510 Another generalized kind of number is @dfn{infinity}. Infinity | 4498 Another generalized kind of number is @dfn{infinity}. Infinity |
4525 @end group | 4513 @end group |
4526 @end smallexample | 4514 @end smallexample |
4527 | 4515 |
4528 @noindent | 4516 @noindent |
4529 Since infinity is infinitely large, multiplying it by any finite | 4517 Since infinity is infinitely large, multiplying it by any finite |
4530 number (like @i{-17}) has no effect, except that since @i{-17} | 4518 number (like @mathit{-17}) has no effect, except that since @mathit{-17} |
4531 is negative, it changes a plus infinity to a minus infinity. | 4519 is negative, it changes a plus infinity to a minus infinity. |
4532 (``A huge positive number, multiplied by @i{-17}, yields a huge | 4520 (``A huge positive number, multiplied by @mathit{-17}, yields a huge |
4533 negative number.'') Adding any finite number to infinity also | 4521 negative number.'') Adding any finite number to infinity also |
4534 leaves it unchanged. Taking an absolute value gives us plus | 4522 leaves it unchanged. Taking an absolute value gives us plus |
4535 infinity again. Finally, we add this plus infinity to the minus | 4523 infinity again. Finally, we add this plus infinity to the minus |
4536 infinity we had earlier. If you work it out, you might expect | 4524 infinity we had earlier. If you work it out, you might expect |
4537 the answer to be @i{-72} for this. But the 72 has been completely | 4525 the answer to be @mathit{-72} for this. But the 72 has been completely |
4538 lost next to the infinities; by the time we compute @w{@samp{inf - inf}} | 4526 lost next to the infinities; by the time we compute @w{@samp{inf - inf}} |
4539 the finite difference between them, if any, is undetectable. | 4527 the finite difference between them, if any, is undetectable. |
4540 So we say the result is @dfn{indeterminate}, which Calc writes | 4528 So we say the result is @dfn{indeterminate}, which Calc writes |
4541 with the symbol @code{nan} (for Not A Number). | 4529 with the symbol @code{nan} (for Not A Number). |
4542 | 4530 |
4689 original error estimates were valid standard deviations, there is about | 4677 original error estimates were valid standard deviations, there is about |
4690 a 60% chance that the result is correct within 0.59 degrees. | 4678 a 60% chance that the result is correct within 0.59 degrees. |
4691 | 4679 |
4692 @cindex Torus, volume of | 4680 @cindex Torus, volume of |
4693 (@bullet{}) @strong{Exercise 7.} The volume of a torus (a donut shape) is | 4681 (@bullet{}) @strong{Exercise 7.} The volume of a torus (a donut shape) is |
4694 @texline @tmath{2 \pi^2 R r^2} | 4682 @texline @math{2 \pi^2 R r^2} |
4695 @infoline @w{@expr{2 pi^2 R r^2}} | 4683 @infoline @w{@expr{2 pi^2 R r^2}} |
4696 where @expr{R} is the radius of the circle that | 4684 where @expr{R} is the radius of the circle that |
4697 defines the center of the tube and @expr{r} is the radius of the tube | 4685 defines the center of the tube and @expr{r} is the radius of the tube |
4698 itself. Suppose @expr{R} is 20 cm and @expr{r} is 4 cm, each known to | 4686 itself. Suppose @expr{R} is 20 cm and @expr{r} is 4 cm, each known to |
4699 within 5 percent. What is the volume and the relative uncertainty of | 4687 within 5 percent. What is the volume and the relative uncertainty of |
4789 that arises in the second one. | 4777 that arises in the second one. |
4790 | 4778 |
4791 @cindex Fermat, primality test of | 4779 @cindex Fermat, primality test of |
4792 (@bullet{}) @strong{Exercise 10.} A theorem of Pierre de Fermat | 4780 (@bullet{}) @strong{Exercise 10.} A theorem of Pierre de Fermat |
4793 says that | 4781 says that |
4794 @texline @w{@tmath{x^{n-1} \bmod n = 1}} | 4782 @texline @w{@math{x^{n-1} \bmod n = 1}} |
4795 @infoline @expr{x^(n-1) mod n = 1} | 4783 @infoline @expr{x^(n-1) mod n = 1} |
4796 if @expr{n} is a prime number and @expr{x} is an integer less than | 4784 if @expr{n} is a prime number and @expr{x} is an integer less than |
4797 @expr{n}. If @expr{n} is @emph{not} a prime number, this will | 4785 @expr{n}. If @expr{n} is @emph{not} a prime number, this will |
4798 @emph{not} be true for most values of @expr{x}. Thus we can test | 4786 @emph{not} be true for most values of @expr{x}. Thus we can test |
4799 informally if a number is prime by trying this formula for several | 4787 informally if a number is prime by trying this formula for several |
4817 @noindent | 4805 @noindent |
4818 This calculation tells me it is six hours and 22 minutes until midnight. | 4806 This calculation tells me it is six hours and 22 minutes until midnight. |
4819 | 4807 |
4820 (@bullet{}) @strong{Exercise 11.} A rule of thumb is that one year | 4808 (@bullet{}) @strong{Exercise 11.} A rule of thumb is that one year |
4821 is about | 4809 is about |
4822 @texline @tmath{\pi \times 10^7} | 4810 @texline @math{\pi \times 10^7} |
4823 @infoline @w{@expr{pi * 10^7}} | 4811 @infoline @w{@expr{pi * 10^7}} |
4824 seconds. What time will it be that many seconds from right now? | 4812 seconds. What time will it be that many seconds from right now? |
4825 @xref{Types Answer 11, 11}. (@bullet{}) | 4813 @xref{Types Answer 11, 11}. (@bullet{}) |
4826 | 4814 |
4827 (@bullet{}) @strong{Exercise 12.} You are preparing to order packaging | 4815 (@bullet{}) @strong{Exercise 12.} You are preparing to order packaging |
5124 @end group | 5112 @end group |
5125 @end smallexample | 5113 @end smallexample |
5126 | 5114 |
5127 @noindent | 5115 @noindent |
5128 Calc has invented the variable @samp{s1} to represent an unknown sign; | 5116 Calc has invented the variable @samp{s1} to represent an unknown sign; |
5129 it is supposed to be either @i{+1} or @i{-1}. Here we have used | 5117 it is supposed to be either @mathit{+1} or @mathit{-1}. Here we have used |
5130 the ``let'' command to evaluate the expression when the sign is negative. | 5118 the ``let'' command to evaluate the expression when the sign is negative. |
5131 If we plugged this into our second derivative we would get the same, | 5119 If we plugged this into our second derivative we would get the same, |
5132 negative, answer, so @expr{x = -1.19023} is also a maximum. | 5120 negative, answer, so @expr{x = -1.19023} is also a maximum. |
5133 | 5121 |
5134 To find the actual maximum value, we must plug our two values of @expr{x} | 5122 To find the actual maximum value, we must plug our two values of @expr{x} |
5294 @end group | 5282 @end group |
5295 @end smallexample | 5283 @end smallexample |
5296 | 5284 |
5297 (@bullet{}) @strong{Exercise 3.} Find the integral from 1 to @expr{y} | 5285 (@bullet{}) @strong{Exercise 3.} Find the integral from 1 to @expr{y} |
5298 of | 5286 of |
5299 @texline @tmath{x \sin \pi x} | 5287 @texline @math{x \sin \pi x} |
5300 @infoline @w{@expr{x sin(pi x)}} | 5288 @infoline @w{@expr{x sin(pi x)}} |
5301 (where the sine is calculated in radians). Find the values of the | 5289 (where the sine is calculated in radians). Find the values of the |
5302 integral for integers @expr{y} from 1 to 5. @xref{Algebra Answer 3, | 5290 integral for integers @expr{y} from 1 to 5. @xref{Algebra Answer 3, |
5303 3}. (@bullet{}) | 5291 3}. (@bullet{}) |
5304 | 5292 |
5305 Calc's integrator can do many simple integrals symbolically, but many | 5293 Calc's integrator can do many simple integrals symbolically, but many |
5306 others are beyond its capabilities. Suppose we wish to find the area | 5294 others are beyond its capabilities. Suppose we wish to find the area |
5307 under the curve | 5295 under the curve |
5308 @texline @tmath{\sin x \ln x} | 5296 @texline @math{\sin x \ln x} |
5309 @infoline @expr{sin(x) ln(x)} | 5297 @infoline @expr{sin(x) ln(x)} |
5310 over the same range of @expr{x}. If you entered this formula and typed | 5298 over the same range of @expr{x}. If you entered this formula and typed |
5311 @kbd{a i x @key{RET}} (don't bother to try this), Calc would work for a | 5299 @kbd{a i x @key{RET}} (don't bother to try this), Calc would work for a |
5312 long time but would be unable to find a solution. In fact, there is no | 5300 long time but would be unable to find a solution. In fact, there is no |
5313 closed-form solution to this integral. Now what do we do? | 5301 closed-form solution to this integral. Now what do we do? |
5445 + f(a+(n-2)h) + f(a+(n-1)h)) $$ | 5433 + f(a+(n-2)h) + f(a+(n-1)h)) $$ |
5446 \afterdisplay | 5434 \afterdisplay |
5447 @end tex | 5435 @end tex |
5448 | 5436 |
5449 Compute the integral from 1 to 2 of | 5437 Compute the integral from 1 to 2 of |
5450 @texline @tmath{\sin x \ln x} | 5438 @texline @math{\sin x \ln x} |
5451 @infoline @expr{sin(x) ln(x)} | 5439 @infoline @expr{sin(x) ln(x)} |
5452 using Simpson's rule with 10 slices. | 5440 using Simpson's rule with 10 slices. |
5453 @xref{Algebra Answer 4, 4}. (@bullet{}) | 5441 @xref{Algebra Answer 4, 4}. (@bullet{}) |
5454 | 5442 |
5455 Calc has a built-in @kbd{a I} command for doing numerical integration. | 5443 Calc has a built-in @kbd{a I} command for doing numerical integration. |
5991 @ignore | 5979 @ignore |
5992 @starindex | 5980 @starindex |
5993 @end ignore | 5981 @end ignore |
5994 @tindex Si | 5982 @tindex Si |
5995 (@bullet{}) @strong{Exercise 1.} The ``sine integral'' function | 5983 (@bullet{}) @strong{Exercise 1.} The ``sine integral'' function |
5996 @texline @tmath{{\rm Si}(x)} | 5984 @texline @math{{\rm Si}(x)} |
5997 @infoline @expr{Si(x)} | 5985 @infoline @expr{Si(x)} |
5998 is defined as the integral of @samp{sin(t)/t} for | 5986 is defined as the integral of @samp{sin(t)/t} for |
5999 @expr{t = 0} to @expr{x} in radians. (It was invented because this | 5987 @expr{t = 0} to @expr{x} in radians. (It was invented because this |
6000 integral has no solution in terms of basic functions; if you give it | 5988 integral has no solution in terms of basic functions; if you give it |
6001 to Calc's @kbd{a i} command, it will ponder it for a long time and then | 5989 to Calc's @kbd{a i} command, it will ponder it for a long time and then |
6069 the following functions: | 6057 the following functions: |
6070 | 6058 |
6071 @enumerate | 6059 @enumerate |
6072 @item | 6060 @item |
6073 Compute | 6061 Compute |
6074 @texline @tmath{\displaystyle{\sin x \over x}}, | 6062 @texline @math{\displaystyle{\sin x \over x}}, |
6075 @infoline @expr{sin(x) / x}, | 6063 @infoline @expr{sin(x) / x}, |
6076 where @expr{x} is the number on the top of the stack. | 6064 where @expr{x} is the number on the top of the stack. |
6077 | 6065 |
6078 @item | 6066 @item |
6079 Compute the base-@expr{b} logarithm, just like the @kbd{B} key except | 6067 Compute the base-@expr{b} logarithm, just like the @kbd{B} key except |
6135 | 6123 |
6136 @cindex Golden ratio | 6124 @cindex Golden ratio |
6137 @cindex Phi, golden ratio | 6125 @cindex Phi, golden ratio |
6138 A fascinating property of the Fibonacci numbers is that the @expr{n}th | 6126 A fascinating property of the Fibonacci numbers is that the @expr{n}th |
6139 Fibonacci number can be found directly by computing | 6127 Fibonacci number can be found directly by computing |
6140 @texline @tmath{\phi^n / \sqrt{5}} | 6128 @texline @math{\phi^n / \sqrt{5}} |
6141 @infoline @expr{phi^n / sqrt(5)} | 6129 @infoline @expr{phi^n / sqrt(5)} |
6142 and then rounding to the nearest integer, where | 6130 and then rounding to the nearest integer, where |
6143 @texline @tmath{\phi} (``phi''), | 6131 @texline @math{\phi} (``phi''), |
6144 @infoline @expr{phi}, | 6132 @infoline @expr{phi}, |
6145 the ``golden ratio,'' is | 6133 the ``golden ratio,'' is |
6146 @texline @tmath{(1 + \sqrt{5}) / 2}. | 6134 @texline @math{(1 + \sqrt{5}) / 2}. |
6147 @infoline @expr{(1 + sqrt(5)) / 2}. | 6135 @infoline @expr{(1 + sqrt(5)) / 2}. |
6148 (For convenience, this constant is available from the @code{phi} | 6136 (For convenience, this constant is available from the @code{phi} |
6149 variable, or the @kbd{I H P} command.) | 6137 variable, or the @kbd{I H P} command.) |
6150 | 6138 |
6151 @smallexample | 6139 @smallexample |
6158 @end smallexample | 6146 @end smallexample |
6159 | 6147 |
6160 @cindex Continued fractions | 6148 @cindex Continued fractions |
6161 (@bullet{}) @strong{Exercise 5.} The @dfn{continued fraction} | 6149 (@bullet{}) @strong{Exercise 5.} The @dfn{continued fraction} |
6162 representation of | 6150 representation of |
6163 @texline @tmath{\phi} | 6151 @texline @math{\phi} |
6164 @infoline @expr{phi} | 6152 @infoline @expr{phi} |
6165 is | 6153 is |
6166 @texline @tmath{1 + 1/(1 + 1/(1 + 1/( \ldots )))}. | 6154 @texline @math{1 + 1/(1 + 1/(1 + 1/( \ldots )))}. |
6167 @infoline @expr{1 + 1/(1 + 1/(1 + 1/( ...@: )))}. | 6155 @infoline @expr{1 + 1/(1 + 1/(1 + 1/( ...@: )))}. |
6168 We can compute an approximate value by carrying this however far | 6156 We can compute an approximate value by carrying this however far |
6169 and then replacing the innermost | 6157 and then replacing the innermost |
6170 @texline @tmath{1/( \ldots )} | 6158 @texline @math{1/( \ldots )} |
6171 @infoline @expr{1/( ...@: )} | 6159 @infoline @expr{1/( ...@: )} |
6172 by 1. Approximate | 6160 by 1. Approximate |
6173 @texline @tmath{\phi} | 6161 @texline @math{\phi} |
6174 @infoline @expr{phi} | 6162 @infoline @expr{phi} |
6175 using a twenty-term continued fraction. | 6163 using a twenty-term continued fraction. |
6176 @xref{Programming Answer 5, 5}. (@bullet{}) | 6164 @xref{Programming Answer 5, 5}. (@bullet{}) |
6177 | 6165 |
6178 (@bullet{}) @strong{Exercise 6.} Linear recurrences like the one for | 6166 (@bullet{}) @strong{Exercise 6.} Linear recurrences like the one for |
6268 @cindex Bernoulli numbers, approximate | 6256 @cindex Bernoulli numbers, approximate |
6269 The @dfn{Bernoulli numbers} are a sequence with the interesting | 6257 The @dfn{Bernoulli numbers} are a sequence with the interesting |
6270 property that all of the odd Bernoulli numbers are zero, and the | 6258 property that all of the odd Bernoulli numbers are zero, and the |
6271 even ones, while difficult to compute, can be roughly approximated | 6259 even ones, while difficult to compute, can be roughly approximated |
6272 by the formula | 6260 by the formula |
6273 @texline @tmath{\displaystyle{2 n! \over (2 \pi)^n}}. | 6261 @texline @math{\displaystyle{2 n! \over (2 \pi)^n}}. |
6274 @infoline @expr{2 n!@: / (2 pi)^n}. | 6262 @infoline @expr{2 n!@: / (2 pi)^n}. |
6275 Let's write a keyboard macro to compute (approximate) Bernoulli numbers. | 6263 Let's write a keyboard macro to compute (approximate) Bernoulli numbers. |
6276 (Calc has a command, @kbd{k b}, to compute exact Bernoulli numbers, but | 6264 (Calc has a command, @kbd{k b}, to compute exact Bernoulli numbers, but |
6277 this command is very slow for large @expr{n} since the higher Bernoulli | 6265 this command is very slow for large @expr{n} since the higher Bernoulli |
6278 numbers are very large fractions.) | 6266 numbers are very large fractions.) |
6442 @end tex | 6430 @end tex |
6443 | 6431 |
6444 @noindent | 6432 @noindent |
6445 where @expr{f'(x)} is the derivative of @expr{f}. The @expr{x} | 6433 where @expr{f'(x)} is the derivative of @expr{f}. The @expr{x} |
6446 values will quickly converge to a solution, i.e., eventually | 6434 values will quickly converge to a solution, i.e., eventually |
6447 @texline @tmath{x_{\rm new}} | 6435 @texline @math{x_{\rm new}} |
6448 @infoline @expr{new_x} | 6436 @infoline @expr{new_x} |
6449 and @expr{x} will be equal to within the limits | 6437 and @expr{x} will be equal to within the limits |
6450 of the current precision. Write a program which takes a formula | 6438 of the current precision. Write a program which takes a formula |
6451 involving the variable @expr{x}, and an initial guess @expr{x_0}, | 6439 involving the variable @expr{x}, and an initial guess @expr{x_0}, |
6452 on the stack, and produces a value of @expr{x} for which the formula | 6440 on the stack, and produces a value of @expr{x} for which the formula |
6453 is zero. Use it to find a solution of | 6441 is zero. Use it to find a solution of |
6454 @texline @tmath{\sin(\cos x) = 0.5} | 6442 @texline @math{\sin(\cos x) = 0.5} |
6455 @infoline @expr{sin(cos(x)) = 0.5} | 6443 @infoline @expr{sin(cos(x)) = 0.5} |
6456 near @expr{x = 4.5}. (Use angles measured in radians.) Note that | 6444 near @expr{x = 4.5}. (Use angles measured in radians.) Note that |
6457 the built-in @w{@kbd{a R}} (@code{calc-find-root}) command uses Newton's | 6445 the built-in @w{@kbd{a R}} (@code{calc-find-root}) command uses Newton's |
6458 method when it is able. @xref{Programming Answer 8, 8}. (@bullet{}) | 6446 method when it is able. @xref{Programming Answer 8, 8}. (@bullet{}) |
6459 | 6447 |
6460 @cindex Digamma function | 6448 @cindex Digamma function |
6461 @cindex Gamma constant, Euler's | 6449 @cindex Gamma constant, Euler's |
6462 @cindex Euler's gamma constant | 6450 @cindex Euler's gamma constant |
6463 (@bullet{}) @strong{Exercise 9.} The @dfn{digamma} function | 6451 (@bullet{}) @strong{Exercise 9.} The @dfn{digamma} function |
6464 @texline @tmath{\psi(z) (``psi'')} | 6452 @texline @math{\psi(z) (``psi'')} |
6465 @infoline @expr{psi(z)} | 6453 @infoline @expr{psi(z)} |
6466 is defined as the derivative of | 6454 is defined as the derivative of |
6467 @texline @tmath{\ln \Gamma(z)}. | 6455 @texline @math{\ln \Gamma(z)}. |
6468 @infoline @expr{ln(gamma(z))}. | 6456 @infoline @expr{ln(gamma(z))}. |
6469 For large values of @expr{z}, it can be approximated by the infinite sum | 6457 For large values of @expr{z}, it can be approximated by the infinite sum |
6470 | 6458 |
6471 @ifinfo | 6459 @ifinfo |
6472 @example | 6460 @example |
6481 \afterdisplay | 6469 \afterdisplay |
6482 @end tex | 6470 @end tex |
6483 | 6471 |
6484 @noindent | 6472 @noindent |
6485 where | 6473 where |
6486 @texline @tmath{\sum} | 6474 @texline @math{\sum} |
6487 @infoline @expr{sum} | 6475 @infoline @expr{sum} |
6488 represents the sum over @expr{n} from 1 to infinity | 6476 represents the sum over @expr{n} from 1 to infinity |
6489 (or to some limit high enough to give the desired accuracy), and | 6477 (or to some limit high enough to give the desired accuracy), and |
6490 the @code{bern} function produces (exact) Bernoulli numbers. | 6478 the @code{bern} function produces (exact) Bernoulli numbers. |
6491 While this sum is not guaranteed to converge, in practice it is safe. | 6479 While this sum is not guaranteed to converge, in practice it is safe. |
6492 An interesting mathematical constant is Euler's gamma, which is equal | 6480 An interesting mathematical constant is Euler's gamma, which is equal |
6493 to about 0.5772. One way to compute it is by the formula, | 6481 to about 0.5772. One way to compute it is by the formula, |
6494 @texline @tmath{\gamma = -\psi(1)}. | 6482 @texline @math{\gamma = -\psi(1)}. |
6495 @infoline @expr{gamma = -psi(1)}. | 6483 @infoline @expr{gamma = -psi(1)}. |
6496 Unfortunately, 1 isn't a large enough argument | 6484 Unfortunately, 1 isn't a large enough argument |
6497 for the above formula to work (5 is a much safer value for @expr{z}). | 6485 for the above formula to work (5 is a much safer value for @expr{z}). |
6498 Fortunately, we can compute | 6486 Fortunately, we can compute |
6499 @texline @tmath{\psi(1)} | 6487 @texline @math{\psi(1)} |
6500 @infoline @expr{psi(1)} | 6488 @infoline @expr{psi(1)} |
6501 from | 6489 from |
6502 @texline @tmath{\psi(5)} | 6490 @texline @math{\psi(5)} |
6503 @infoline @expr{psi(5)} | 6491 @infoline @expr{psi(5)} |
6504 using the recurrence | 6492 using the recurrence |
6505 @texline @tmath{\psi(z+1) = \psi(z) + {1 \over z}}. | 6493 @texline @math{\psi(z+1) = \psi(z) + {1 \over z}}. |
6506 @infoline @expr{psi(z+1) = psi(z) + 1/z}. | 6494 @infoline @expr{psi(z+1) = psi(z) + 1/z}. |
6507 Your task: Develop a program to compute | 6495 Your task: Develop a program to compute |
6508 @texline @tmath{\psi(z)}; | 6496 @texline @math{\psi(z)}; |
6509 @infoline @expr{psi(z)}; | 6497 @infoline @expr{psi(z)}; |
6510 it should ``pump up'' @expr{z} | 6498 it should ``pump up'' @expr{z} |
6511 if necessary to be greater than 5, then use the above summation | 6499 if necessary to be greater than 5, then use the above summation |
6512 formula. Use looping commands to compute the sum. Use your function | 6500 formula. Use looping commands to compute the sum. Use your function |
6513 to compute | 6501 to compute |
6514 @texline @tmath{\gamma} | 6502 @texline @math{\gamma} |
6515 @infoline @expr{gamma} | 6503 @infoline @expr{gamma} |
6516 to twelve decimal places. (Calc has a built-in command | 6504 to twelve decimal places. (Calc has a built-in command |
6517 for Euler's constant, @kbd{I P}, which you can use to check your answer.) | 6505 for Euler's constant, @kbd{I P}, which you can use to check your answer.) |
6518 @xref{Programming Answer 9, 9}. (@bullet{}) | 6506 @xref{Programming Answer 9, 9}. (@bullet{}) |
6519 | 6507 |
6686 | 6674 |
6687 @noindent | 6675 @noindent |
6688 @kbd{1 @key{RET} 2 @key{RET} 3 @key{RET} 4 + * -} | 6676 @kbd{1 @key{RET} 2 @key{RET} 3 @key{RET} 4 + * -} |
6689 | 6677 |
6690 The result is | 6678 The result is |
6691 @texline @tmath{1 - (2 \times (3 + 4)) = -13}. | 6679 @texline @math{1 - (2 \times (3 + 4)) = -13}. |
6692 @infoline @expr{1 - (2 * (3 + 4)) = -13}. | 6680 @infoline @expr{1 - (2 * (3 + 4)) = -13}. |
6693 | 6681 |
6694 @node RPN Answer 2, RPN Answer 3, RPN Answer 1, Answers to Exercises | 6682 @node RPN Answer 2, RPN Answer 3, RPN Answer 1, Answers to Exercises |
6695 @subsection RPN Tutorial Exercise 2 | 6683 @subsection RPN Tutorial Exercise 2 |
6696 | 6684 |
6697 @noindent | 6685 @noindent |
6698 @texline @tmath{2\times4 + 7\times9.5 + {5\over4} = 75.75} | 6686 @texline @math{2\times4 + 7\times9.5 + {5\over4} = 75.75} |
6699 @infoline @expr{2*4 + 7*9.5 + 5/4 = 75.75} | 6687 @infoline @expr{2*4 + 7*9.5 + 5/4 = 75.75} |
6700 | 6688 |
6701 After computing the intermediate term | 6689 After computing the intermediate term |
6702 @texline @tmath{2\times4 = 8}, | 6690 @texline @math{2\times4 = 8}, |
6703 @infoline @expr{2*4 = 8}, | 6691 @infoline @expr{2*4 = 8}, |
6704 you can leave that result on the stack while you compute the second | 6692 you can leave that result on the stack while you compute the second |
6705 term. With both of these results waiting on the stack you can then | 6693 term. With both of these results waiting on the stack you can then |
6706 compute the final term, then press @kbd{+ +} to add everything up. | 6694 compute the final term, then press @kbd{+ +} to add everything up. |
6707 | 6695 |
7006 Dividing two integers that are larger than the current precision may | 6994 Dividing two integers that are larger than the current precision may |
7007 give a floating-point result that is inaccurate even when rounded | 6995 give a floating-point result that is inaccurate even when rounded |
7008 down to an integer. Consider @expr{123456789 / 2} when the current | 6996 down to an integer. Consider @expr{123456789 / 2} when the current |
7009 precision is 6 digits. The true answer is @expr{61728394.5}, but | 6997 precision is 6 digits. The true answer is @expr{61728394.5}, but |
7010 with a precision of 6 this will be rounded to | 6998 with a precision of 6 this will be rounded to |
7011 @texline @tmath{12345700.0/2.0 = 61728500.0}. | 6999 @texline @math{12345700.0/2.0 = 61728500.0}. |
7012 @infoline @expr{12345700.@: / 2.@: = 61728500.}. | 7000 @infoline @expr{12345700.@: / 2.@: = 61728500.}. |
7013 The result, when converted to an integer, will be off by 106. | 7001 The result, when converted to an integer, will be off by 106. |
7014 | 7002 |
7015 Here are two solutions: Raise the precision enough that the | 7003 Here are two solutions: Raise the precision enough that the |
7016 floating-point round-off error is strictly to the right of the | 7004 floating-point round-off error is strictly to the right of the |
7117 @node Matrix Answer 3, List Answer 1, Matrix Answer 2, Answers to Exercises | 7105 @node Matrix Answer 3, List Answer 1, Matrix Answer 2, Answers to Exercises |
7118 @subsection Matrix Tutorial Exercise 3 | 7106 @subsection Matrix Tutorial Exercise 3 |
7119 | 7107 |
7120 @noindent | 7108 @noindent |
7121 To solve | 7109 To solve |
7122 @texline @tmath{A^T A \, X = A^T B}, | 7110 @texline @math{A^T A \, X = A^T B}, |
7123 @infoline @expr{trn(A) * A * X = trn(A) * B}, | 7111 @infoline @expr{trn(A) * A * X = trn(A) * B}, |
7124 first we compute | 7112 first we compute |
7125 @texline @tmath{A' = A^T A} | 7113 @texline @math{A' = A^T A} |
7126 @infoline @expr{A2 = trn(A) * A} | 7114 @infoline @expr{A2 = trn(A) * A} |
7127 and | 7115 and |
7128 @texline @tmath{B' = A^T B}; | 7116 @texline @math{B' = A^T B}; |
7129 @infoline @expr{B2 = trn(A) * B}; | 7117 @infoline @expr{B2 = trn(A) * B}; |
7130 now, we have a system | 7118 now, we have a system |
7131 @texline @tmath{A' X = B'} | 7119 @texline @math{A' X = B'} |
7132 @infoline @expr{A2 * X = B2} | 7120 @infoline @expr{A2 * X = B2} |
7133 which we can solve using Calc's @samp{/} command. | 7121 which we can solve using Calc's @samp{/} command. |
7134 | 7122 |
7135 @ifinfo | 7123 @ifinfo |
7136 @example | 7124 @example |
7158 \afterdisplayh | 7146 \afterdisplayh |
7159 @end tex | 7147 @end tex |
7160 | 7148 |
7161 The first step is to enter the coefficient matrix. We'll store it in | 7149 The first step is to enter the coefficient matrix. We'll store it in |
7162 quick variable number 7 for later reference. Next, we compute the | 7150 quick variable number 7 for later reference. Next, we compute the |
7163 @texline @tmath{B'} | 7151 @texline @math{B'} |
7164 @infoline @expr{B2} | 7152 @infoline @expr{B2} |
7165 vector. | 7153 vector. |
7166 | 7154 |
7167 @smallexample | 7155 @smallexample |
7168 @group | 7156 @group |
7176 @end group | 7164 @end group |
7177 @end smallexample | 7165 @end smallexample |
7178 | 7166 |
7179 @noindent | 7167 @noindent |
7180 Now we compute the matrix | 7168 Now we compute the matrix |
7181 @texline @tmath{A'} | 7169 @texline @math{A'} |
7182 @infoline @expr{A2} | 7170 @infoline @expr{A2} |
7183 and divide. | 7171 and divide. |
7184 | 7172 |
7185 @smallexample | 7173 @smallexample |
7186 @group | 7174 @group |
7197 @noindent | 7185 @noindent |
7198 (The actual computed answer will be slightly inexact due to | 7186 (The actual computed answer will be slightly inexact due to |
7199 round-off error.) | 7187 round-off error.) |
7200 | 7188 |
7201 Notice that the answers are similar to those for the | 7189 Notice that the answers are similar to those for the |
7202 @texline @tmath{3\times3} | 7190 @texline @math{3\times3} |
7203 @infoline 3x3 | 7191 @infoline 3x3 |
7204 system solved in the text. That's because the fourth equation that was | 7192 system solved in the text. That's because the fourth equation that was |
7205 added to the system is almost identical to the first one multiplied | 7193 added to the system is almost identical to the first one multiplied |
7206 by two. (If it were identical, we would have gotten the exact same | 7194 by two. (If it were identical, we would have gotten the exact same |
7207 answer since the | 7195 answer since the |
7208 @texline @tmath{4\times3} | 7196 @texline @math{4\times3} |
7209 @infoline 4x3 | 7197 @infoline 4x3 |
7210 system would be equivalent to the original | 7198 system would be equivalent to the original |
7211 @texline @tmath{3\times3} | 7199 @texline @math{3\times3} |
7212 @infoline 3x3 | 7200 @infoline 3x3 |
7213 system.) | 7201 system.) |
7214 | 7202 |
7215 Since the first and fourth equations aren't quite equivalent, they | 7203 Since the first and fourth equations aren't quite equivalent, they |
7216 can't both be satisfied at once. Let's plug our answers back into | 7204 can't both be satisfied at once. Let's plug our answers back into |
7283 $$ m \times x + b \times 1 = y $$ | 7271 $$ m \times x + b \times 1 = y $$ |
7284 \afterdisplay | 7272 \afterdisplay |
7285 @end tex | 7273 @end tex |
7286 | 7274 |
7287 Thus we want a | 7275 Thus we want a |
7288 @texline @tmath{19\times2} | 7276 @texline @math{19\times2} |
7289 @infoline 19x2 | 7277 @infoline 19x2 |
7290 matrix with our @expr{x} vector as one column and | 7278 matrix with our @expr{x} vector as one column and |
7291 ones as the other column. So, first we build the column of ones, then | 7279 ones as the other column. So, first we build the column of ones, then |
7292 we combine the two columns to form our @expr{A} matrix. | 7280 we combine the two columns to form our @expr{A} matrix. |
7293 | 7281 |
7302 @end group | 7290 @end group |
7303 @end smallexample | 7291 @end smallexample |
7304 | 7292 |
7305 @noindent | 7293 @noindent |
7306 Now we compute | 7294 Now we compute |
7307 @texline @tmath{A^T y} | 7295 @texline @math{A^T y} |
7308 @infoline @expr{trn(A) * y} | 7296 @infoline @expr{trn(A) * y} |
7309 and | 7297 and |
7310 @texline @tmath{A^T A} | 7298 @texline @math{A^T A} |
7311 @infoline @expr{trn(A) * A} | 7299 @infoline @expr{trn(A) * A} |
7312 and divide. | 7300 and divide. |
7313 | 7301 |
7314 @smallexample | 7302 @smallexample |
7315 @group | 7303 @group |
7333 / | 7321 / |
7334 @end group | 7322 @end group |
7335 @end smallexample | 7323 @end smallexample |
7336 | 7324 |
7337 Since we were solving equations of the form | 7325 Since we were solving equations of the form |
7338 @texline @tmath{m \times x + b \times 1 = y}, | 7326 @texline @math{m \times x + b \times 1 = y}, |
7339 @infoline @expr{m*x + b*1 = y}, | 7327 @infoline @expr{m*x + b*1 = y}, |
7340 these numbers should be @expr{m} and @expr{b}, respectively. Sure | 7328 these numbers should be @expr{m} and @expr{b}, respectively. Sure |
7341 enough, they agree exactly with the result computed using @kbd{V M} and | 7329 enough, they agree exactly with the result computed using @kbd{V M} and |
7342 @kbd{V R}! | 7330 @kbd{V R}! |
7343 | 7331 |
7396 @node List Answer 4, List Answer 5, List Answer 3, Answers to Exercises | 7384 @node List Answer 4, List Answer 5, List Answer 3, Answers to Exercises |
7397 @subsection List Tutorial Exercise 4 | 7385 @subsection List Tutorial Exercise 4 |
7398 | 7386 |
7399 @noindent | 7387 @noindent |
7400 A number @expr{j} is a divisor of @expr{n} if | 7388 A number @expr{j} is a divisor of @expr{n} if |
7401 @texline @tmath{n \mathbin{\hbox{\code{\%}}} j = 0}. | 7389 @texline @math{n \mathbin{\hbox{\code{\%}}} j = 0}. |
7402 @infoline @samp{n % j = 0}. | 7390 @infoline @samp{n % j = 0}. |
7403 The first step is to get a vector that identifies the divisors. | 7391 The first step is to get a vector that identifies the divisors. |
7404 | 7392 |
7405 @smallexample | 7393 @smallexample |
7406 @group | 7394 @group |
7467 so that the mapping operation works; no prime factor will ever be | 7455 so that the mapping operation works; no prime factor will ever be |
7468 zero, so adding zeros on the left and right is safe. From then on | 7456 zero, so adding zeros on the left and right is safe. From then on |
7469 the job is pretty straightforward. | 7457 the job is pretty straightforward. |
7470 | 7458 |
7471 Incidentally, Calc provides the | 7459 Incidentally, Calc provides the |
7472 @texline @dfn{M@"obius} @tmath{\mu} | 7460 @texline @dfn{M@"obius} @math{\mu} |
7473 @infoline @dfn{Moebius mu} | 7461 @infoline @dfn{Moebius mu} |
7474 function which is zero if and only if its argument is square-free. It | 7462 function which is zero if and only if its argument is square-free. It |
7475 would be a much more convenient way to do the above test in practice. | 7463 would be a much more convenient way to do the above test in practice. |
7476 | 7464 |
7477 @node List Answer 6, List Answer 7, List Answer 5, Answers to Exercises | 7465 @node List Answer 6, List Answer 7, List Answer 5, Answers to Exercises |
7501 | 7489 |
7502 The numbers down the lefthand edge of the list we desire are called | 7490 The numbers down the lefthand edge of the list we desire are called |
7503 the ``triangular numbers'' (now you know why!). The @expr{n}th | 7491 the ``triangular numbers'' (now you know why!). The @expr{n}th |
7504 triangular number is the sum of the integers from 1 to @expr{n}, and | 7492 triangular number is the sum of the integers from 1 to @expr{n}, and |
7505 can be computed directly by the formula | 7493 can be computed directly by the formula |
7506 @texline @tmath{n (n+1) \over 2}. | 7494 @texline @math{n (n+1) \over 2}. |
7507 @infoline @expr{n * (n+1) / 2}. | 7495 @infoline @expr{n * (n+1) / 2}. |
7508 | 7496 |
7509 @smallexample | 7497 @smallexample |
7510 @group | 7498 @group |
7511 2: [ [0], [0, 1], ... ] 2: [ [0], [0, 1], ... ] | 7499 2: [ [0], [0, 1], ... ] 2: [ [0], [0, 1], ... ] |
7597 @end smallexample | 7585 @end smallexample |
7598 | 7586 |
7599 @noindent | 7587 @noindent |
7600 It's a good idea to verify, as in the last step above, that only | 7588 It's a good idea to verify, as in the last step above, that only |
7601 one value is equal to the maximum. (After all, a plot of | 7589 one value is equal to the maximum. (After all, a plot of |
7602 @texline @tmath{\sin x} | 7590 @texline @math{\sin x} |
7603 @infoline @expr{sin(x)} | 7591 @infoline @expr{sin(x)} |
7604 might have many points all equal to the maximum value, 1.) | 7592 might have many points all equal to the maximum value, 1.) |
7605 | 7593 |
7606 The vector we have now has a single 1 in the position that indicates | 7594 The vector we have now has a single 1 in the position that indicates |
7607 the maximum value of @expr{x}. Now it is a simple matter to convert | 7595 the maximum value of @expr{x}. Now it is a simple matter to convert |
7869 @noindent | 7857 @noindent |
7870 This problem can be made a lot easier by taking advantage of some | 7858 This problem can be made a lot easier by taking advantage of some |
7871 symmetries. First of all, after some thought it's clear that the | 7859 symmetries. First of all, after some thought it's clear that the |
7872 @expr{y} axis can be ignored altogether. Just pick a random @expr{x} | 7860 @expr{y} axis can be ignored altogether. Just pick a random @expr{x} |
7873 component for one end of the match, pick a random direction | 7861 component for one end of the match, pick a random direction |
7874 @texline @tmath{\theta}, | 7862 @texline @math{\theta}, |
7875 @infoline @expr{theta}, | 7863 @infoline @expr{theta}, |
7876 and see if @expr{x} and | 7864 and see if @expr{x} and |
7877 @texline @tmath{x + \cos \theta} | 7865 @texline @math{x + \cos \theta} |
7878 @infoline @expr{x + cos(theta)} | 7866 @infoline @expr{x + cos(theta)} |
7879 (which is the @expr{x} coordinate of the other endpoint) cross a line. | 7867 (which is the @expr{x} coordinate of the other endpoint) cross a line. |
7880 The lines are at integer coordinates, so this happens when the two | 7868 The lines are at integer coordinates, so this happens when the two |
7881 numbers surround an integer. | 7869 numbers surround an integer. |
7882 | 7870 |
7889 In fact, since the field of lines is infinite we can choose the | 7877 In fact, since the field of lines is infinite we can choose the |
7890 coordinates 0 and 1 for the lines on either side of the leftmost | 7878 coordinates 0 and 1 for the lines on either side of the leftmost |
7891 endpoint. The rightmost endpoint will be between 0 and 1 if the | 7879 endpoint. The rightmost endpoint will be between 0 and 1 if the |
7892 match does not cross a line, or between 1 and 2 if it does. So: | 7880 match does not cross a line, or between 1 and 2 if it does. So: |
7893 Pick random @expr{x} and | 7881 Pick random @expr{x} and |
7894 @texline @tmath{\theta}, | 7882 @texline @math{\theta}, |
7895 @infoline @expr{theta}, | 7883 @infoline @expr{theta}, |
7896 compute | 7884 compute |
7897 @texline @tmath{x + \cos \theta}, | 7885 @texline @math{x + \cos \theta}, |
7898 @infoline @expr{x + cos(theta)}, | 7886 @infoline @expr{x + cos(theta)}, |
7899 and count how many of the results are greater than one. Simple! | 7887 and count how many of the results are greater than one. Simple! |
7900 | 7888 |
7901 We can make this go a bit faster by using the @kbd{v .} and @kbd{t .} | 7889 We can make this go a bit faster by using the @kbd{v .} and @kbd{t .} |
7902 commands. | 7890 commands. |
8217 @end smallexample | 8205 @end smallexample |
8218 | 8206 |
8219 @noindent | 8207 @noindent |
8220 Aha! It's unlikely that an irrational number would equal a fraction | 8208 Aha! It's unlikely that an irrational number would equal a fraction |
8221 this simple to within ten digits, so our original number was probably | 8209 this simple to within ten digits, so our original number was probably |
8222 @texline @tmath{\sqrt{27 \pi / 53}}. | 8210 @texline @math{\sqrt{27 \pi / 53}}. |
8223 @infoline @expr{sqrt(27 pi / 53)}. | 8211 @infoline @expr{sqrt(27 pi / 53)}. |
8224 | 8212 |
8225 Notice that we didn't need to re-round the number when we reduced the | 8213 Notice that we didn't need to re-round the number when we reduced the |
8226 precision. Remember, arithmetic operations always round their inputs | 8214 precision. Remember, arithmetic operations always round their inputs |
8227 to the current precision before they begin. | 8215 to the current precision before they begin. |
8478 as a possible value. | 8466 as a possible value. |
8479 | 8467 |
8480 The fourth calculation, @samp{1 / (-10 .. 10)}, has the same problem. | 8468 The fourth calculation, @samp{1 / (-10 .. 10)}, has the same problem. |
8481 Zero is buried inside the interval, but it's still a possible value. | 8469 Zero is buried inside the interval, but it's still a possible value. |
8482 It's not hard to see that the actual result of @samp{1 / (-10 .. 10)} | 8470 It's not hard to see that the actual result of @samp{1 / (-10 .. 10)} |
8483 will be either greater than @i{0.1}, or less than @i{-0.1}. Thus | 8471 will be either greater than @mathit{0.1}, or less than @mathit{-0.1}. Thus |
8484 the interval goes from minus infinity to plus infinity, with a ``hole'' | 8472 the interval goes from minus infinity to plus infinity, with a ``hole'' |
8485 in it from @i{-0.1} to @i{0.1}. Calc doesn't have any way to | 8473 in it from @mathit{-0.1} to @mathit{0.1}. Calc doesn't have any way to |
8486 represent this, so it just reports @samp{[-inf .. inf]} as the answer. | 8474 represent this, so it just reports @samp{[-inf .. inf]} as the answer. |
8487 It may be disappointing to hear ``the answer lies somewhere between | 8475 It may be disappointing to hear ``the answer lies somewhere between |
8488 minus infinity and plus infinity, inclusive,'' but that's the best | 8476 minus infinity and plus infinity, inclusive,'' but that's the best |
8489 that interval arithmetic can do in this case. | 8477 that interval arithmetic can do in this case. |
8490 | 8478 |
8500 [ 3 n .. 3 ] @key{RET} 2 ^ @key{TAB} @key{RET} * | 8488 [ 3 n .. 3 ] @key{RET} 2 ^ @key{TAB} @key{RET} * |
8501 @end group | 8489 @end group |
8502 @end smallexample | 8490 @end smallexample |
8503 | 8491 |
8504 @noindent | 8492 @noindent |
8505 In the first case the result says, ``if a number is between @i{-3} and | 8493 In the first case the result says, ``if a number is between @mathit{-3} and |
8506 3, its square is between 0 and 9.'' The second case says, ``the product | 8494 3, its square is between 0 and 9.'' The second case says, ``the product |
8507 of two numbers each between @i{-3} and 3 is between @i{-9} and 9.'' | 8495 of two numbers each between @mathit{-3} and 3 is between @mathit{-9} and 9.'' |
8508 | 8496 |
8509 An interval form is not a number; it is a symbol that can stand for | 8497 An interval form is not a number; it is a symbol that can stand for |
8510 many different numbers. Two identical-looking interval forms can stand | 8498 many different numbers. Two identical-looking interval forms can stand |
8511 for different numbers. | 8499 for different numbers. |
8512 | 8500 |
9258 Each of these functions can be computed using the stack, or using | 9246 Each of these functions can be computed using the stack, or using |
9259 algebraic entry, whichever way you prefer: | 9247 algebraic entry, whichever way you prefer: |
9260 | 9248 |
9261 @noindent | 9249 @noindent |
9262 Computing | 9250 Computing |
9263 @texline @tmath{\displaystyle{\sin x \over x}}: | 9251 @texline @math{\displaystyle{\sin x \over x}}: |
9264 @infoline @expr{sin(x) / x}: | 9252 @infoline @expr{sin(x) / x}: |
9265 | 9253 |
9266 Using the stack: @kbd{C-x ( @key{RET} S @key{TAB} / C-x )}. | 9254 Using the stack: @kbd{C-x ( @key{RET} S @key{TAB} / C-x )}. |
9267 | 9255 |
9268 Using algebraic entry: @kbd{C-x ( ' sin($)/$ @key{RET} C-x )}. | 9256 Using algebraic entry: @kbd{C-x ( ' sin($)/$ @key{RET} C-x )}. |
9329 @end example | 9317 @end example |
9330 | 9318 |
9331 @noindent | 9319 @noindent |
9332 This program is quite efficient because Calc knows how to raise a | 9320 This program is quite efficient because Calc knows how to raise a |
9333 matrix (or other value) to the power @expr{n} in only | 9321 matrix (or other value) to the power @expr{n} in only |
9334 @texline @tmath{\log_2 n} | 9322 @texline @math{\log_2 n} |
9335 @infoline @expr{log(n,2)} | 9323 @infoline @expr{log(n,2)} |
9336 steps. For example, this program can compute the 1000th Fibonacci | 9324 steps. For example, this program can compute the 1000th Fibonacci |
9337 number (a 209-digit integer!) in about 10 steps; even though the | 9325 number (a 209-digit integer!) in about 10 steps; even though the |
9338 @kbd{Z < ... Z >} solution had much simpler steps, it would have | 9326 @kbd{Z < ... Z >} solution had much simpler steps, it would have |
9339 required so many steps that it would not have been practical. | 9327 required so many steps that it would not have been practical. |
9383 @subsection Programming Tutorial Exercise 8 | 9371 @subsection Programming Tutorial Exercise 8 |
9384 | 9372 |
9385 @noindent | 9373 @noindent |
9386 The first step is to compute the derivative @expr{f'(x)} and thus | 9374 The first step is to compute the derivative @expr{f'(x)} and thus |
9387 the formula | 9375 the formula |
9388 @texline @tmath{\displaystyle{x - {f(x) \over f'(x)}}}. | 9376 @texline @math{\displaystyle{x - {f(x) \over f'(x)}}}. |
9389 @infoline @expr{x - f(x)/f'(x)}. | 9377 @infoline @expr{x - f(x)/f'(x)}. |
9390 | 9378 |
9391 (Because this definition is long, it will be repeated in concise form | 9379 (Because this definition is long, it will be repeated in concise form |
9392 below. You can use @w{@kbd{M-# m}} to load it from there. While you are | 9380 below. You can use @w{@kbd{M-# m}} to load it from there. While you are |
9393 entering a @kbd{Z ` Z '} body in a macro, Calc simply collects | 9381 entering a @kbd{Z ` Z '} body in a macro, Calc simply collects |
9500 | 9488 |
9501 @noindent | 9489 @noindent |
9502 The first step is to adjust @expr{z} to be greater than 5. A simple | 9490 The first step is to adjust @expr{z} to be greater than 5. A simple |
9503 ``for'' loop will do the job here. If @expr{z} is less than 5, we | 9491 ``for'' loop will do the job here. If @expr{z} is less than 5, we |
9504 reduce the problem using | 9492 reduce the problem using |
9505 @texline @tmath{\psi(z) = \psi(z+1) - 1/z}. | 9493 @texline @math{\psi(z) = \psi(z+1) - 1/z}. |
9506 @infoline @expr{psi(z) = psi(z+1) - 1/z}. We go | 9494 @infoline @expr{psi(z) = psi(z+1) - 1/z}. We go |
9507 on to compute | 9495 on to compute |
9508 @texline @tmath{\psi(z+1)}, | 9496 @texline @math{\psi(z+1)}, |
9509 @infoline @expr{psi(z+1)}, | 9497 @infoline @expr{psi(z+1)}, |
9510 and remember to add back a factor of @expr{-1/z} when we're done. This | 9498 and remember to add back a factor of @expr{-1/z} when we're done. This |
9511 step is repeated until @expr{z > 5}. | 9499 step is repeated until @expr{z > 5}. |
9512 | 9500 |
9513 (Because this definition is long, it will be repeated in concise form | 9501 (Because this definition is long, it will be repeated in concise form |
9544 @key{RET} 5 a < Z [ 5 Z ( & s + 2 1 s + 1 1 Z ) r 1 Z ] | 9532 @key{RET} 5 a < Z [ 5 Z ( & s + 2 1 s + 1 1 Z ) r 1 Z ] |
9545 @end group | 9533 @end group |
9546 @end smallexample | 9534 @end smallexample |
9547 | 9535 |
9548 Now we compute the initial part of the sum: | 9536 Now we compute the initial part of the sum: |
9549 @texline @tmath{\ln z - {1 \over 2z}} | 9537 @texline @math{\ln z - {1 \over 2z}} |
9550 @infoline @expr{ln(z) - 1/2z} | 9538 @infoline @expr{ln(z) - 1/2z} |
9551 minus the adjustment factor. | 9539 minus the adjustment factor. |
9552 | 9540 |
9553 @smallexample | 9541 @smallexample |
9554 @group | 9542 @group |
9587 @key{TAB} @key{RET} M-@key{TAB} - @key{RET} M-@key{TAB} a = Z / 2 Z ) Z ' C-x ) | 9575 @key{TAB} @key{RET} M-@key{TAB} - @key{RET} M-@key{TAB} a = Z / 2 Z ) Z ' C-x ) |
9588 @end group | 9576 @end group |
9589 @end smallexample | 9577 @end smallexample |
9590 | 9578 |
9591 This is the value of | 9579 This is the value of |
9592 @texline @tmath{-\gamma}, | 9580 @texline @math{-\gamma}, |
9593 @infoline @expr{- gamma}, | 9581 @infoline @expr{- gamma}, |
9594 with a slight bit of roundoff error. To get a full 12 digits, let's use | 9582 with a slight bit of roundoff error. To get a full 12 digits, let's use |
9595 a higher precision: | 9583 a higher precision: |
9596 | 9584 |
9597 @smallexample | 9585 @smallexample |
9622 @subsection Programming Tutorial Exercise 10 | 9610 @subsection Programming Tutorial Exercise 10 |
9623 | 9611 |
9624 @noindent | 9612 @noindent |
9625 Taking the derivative of a term of the form @expr{x^n} will produce | 9613 Taking the derivative of a term of the form @expr{x^n} will produce |
9626 a term like | 9614 a term like |
9627 @texline @tmath{n x^{n-1}}. | 9615 @texline @math{n x^{n-1}}. |
9628 @infoline @expr{n x^(n-1)}. | 9616 @infoline @expr{n x^(n-1)}. |
9629 Taking the derivative of a constant | 9617 Taking the derivative of a constant |
9630 produces zero. From this it is easy to see that the @expr{n}th | 9618 produces zero. From this it is easy to see that the @expr{n}th |
9631 derivative of a polynomial, evaluated at @expr{x = 0}, will equal the | 9619 derivative of a polynomial, evaluated at @expr{x = 0}, will equal the |
9632 coefficient on the @expr{x^n} term times @expr{n!}. | 9620 coefficient on the @expr{x^n} term times @expr{n!}. |
10196 (@key{RET} corresponds to the @key{ENTER} key on most calculators.) | 10184 (@key{RET} corresponds to the @key{ENTER} key on most calculators.) |
10197 The first three keystrokes ``push'' the numbers 1 and 2 onto the stack. The | 10185 The first three keystrokes ``push'' the numbers 1 and 2 onto the stack. The |
10198 @kbd{+} key always ``pops'' the top two numbers from the stack, adds them, | 10186 @kbd{+} key always ``pops'' the top two numbers from the stack, adds them, |
10199 and pushes the result (3) back onto the stack. This number is ready for | 10187 and pushes the result (3) back onto the stack. This number is ready for |
10200 further calculations: @kbd{5 -} pushes 5 onto the stack, then pops the | 10188 further calculations: @kbd{5 -} pushes 5 onto the stack, then pops the |
10201 3 and 5, subtracts them, and pushes the result (@i{-2}). | 10189 3 and 5, subtracts them, and pushes the result (@mathit{-2}). |
10202 | 10190 |
10203 Note that the ``top'' of the stack actually appears at the @emph{bottom} | 10191 Note that the ``top'' of the stack actually appears at the @emph{bottom} |
10204 of the buffer. A line containing a single @samp{.} character signifies | 10192 of the buffer. A line containing a single @samp{.} character signifies |
10205 the end of the buffer; Calculator commands operate on the number(s) | 10193 the end of the buffer; Calculator commands operate on the number(s) |
10206 directly above this line. The @kbd{d t} (@code{calc-truncate-stack}) | 10194 directly above this line. The @kbd{d t} (@code{calc-truncate-stack}) |
10259 @kbd{-}, @kbd{n}, and @kbd{_} (the underscore). The @kbd{-} key subtracts | 10247 @kbd{-}, @kbd{n}, and @kbd{_} (the underscore). The @kbd{-} key subtracts |
10260 the two numbers on the top of the stack. The @kbd{n} key changes the sign | 10248 the two numbers on the top of the stack. The @kbd{n} key changes the sign |
10261 of the number on the top of the stack or the number currently being entered. | 10249 of the number on the top of the stack or the number currently being entered. |
10262 The @kbd{_} key begins entry of a negative number or changes the sign of | 10250 The @kbd{_} key begins entry of a negative number or changes the sign of |
10263 the number currently being entered. The following sequences all enter the | 10251 the number currently being entered. The following sequences all enter the |
10264 number @i{-5} onto the stack: @kbd{0 @key{RET} 5 -}, @kbd{5 n @key{RET}}, | 10252 number @mathit{-5} onto the stack: @kbd{0 @key{RET} 5 -}, @kbd{5 n @key{RET}}, |
10265 @kbd{5 @key{RET} n}, @kbd{_ 5 @key{RET}}, @kbd{5 _ @key{RET}}. | 10253 @kbd{5 @key{RET} n}, @kbd{_ 5 @key{RET}}, @kbd{5 _ @key{RET}}. |
10266 | 10254 |
10267 Some other keys are active during numeric entry, such as @kbd{#} for | 10255 Some other keys are active during numeric entry, such as @kbd{#} for |
10268 non-decimal numbers, @kbd{:} for fractions, and @kbd{@@} for HMS forms. | 10256 non-decimal numbers, @kbd{:} for fractions, and @kbd{@@} for HMS forms. |
10269 These notations are described later in this manual with the corresponding | 10257 These notations are described later in this manual with the corresponding |
10280 @cindex Algebraic notation | 10268 @cindex Algebraic notation |
10281 @cindex Formulas, entering | 10269 @cindex Formulas, entering |
10282 Calculations can also be entered in algebraic form. This is accomplished | 10270 Calculations can also be entered in algebraic form. This is accomplished |
10283 by typing the apostrophe key, @kbd{'}, followed by the expression in | 10271 by typing the apostrophe key, @kbd{'}, followed by the expression in |
10284 standard format: @kbd{@key{'} 2+3*4 @key{RET}} computes | 10272 standard format: @kbd{@key{'} 2+3*4 @key{RET}} computes |
10285 @texline @tmath{2+(3\times4) = 14} | 10273 @texline @math{2+(3\times4) = 14} |
10286 @infoline @expr{2+(3*4) = 14} | 10274 @infoline @expr{2+(3*4) = 14} |
10287 and pushes that on the stack. If you wish you can | 10275 and pushes that on the stack. If you wish you can |
10288 ignore the RPN aspect of Calc altogether and simply enter algebraic | 10276 ignore the RPN aspect of Calc altogether and simply enter algebraic |
10289 expressions in this way. You may want to use @key{DEL} every so often to | 10277 expressions in this way. You may want to use @key{DEL} every so often to |
10290 clear previous results off the stack. | 10278 clear previous results off the stack. |
10690 is greater than this, it will recompute @cpi{} using a series | 10678 is greater than this, it will recompute @cpi{} using a series |
10691 approximation. This value will not need to be recomputed ever again | 10679 approximation. This value will not need to be recomputed ever again |
10692 unless you raise the precision still further. Many operations such as | 10680 unless you raise the precision still further. Many operations such as |
10693 logarithms and sines make use of similarly cached values such as | 10681 logarithms and sines make use of similarly cached values such as |
10694 @cpiover{4} and | 10682 @cpiover{4} and |
10695 @texline @tmath{\ln 2}. | 10683 @texline @math{\ln 2}. |
10696 @infoline @expr{ln(2)}. | 10684 @infoline @expr{ln(2)}. |
10697 The visible effect of caching is that | 10685 The visible effect of caching is that |
10698 high-precision computations may seem to do extra work the first time. | 10686 high-precision computations may seem to do extra work the first time. |
10699 Other things cached include powers of two (for the binary arithmetic | 10687 Other things cached include powers of two (for the binary arithmetic |
10700 functions), matrix inverses and determinants, symbolic integrals, and | 10688 functions), matrix inverses and determinants, symbolic integrals, and |
10849 @cindex Floating-point numbers | 10837 @cindex Floating-point numbers |
10850 A floating-point number or @dfn{float} is a number stored in scientific | 10838 A floating-point number or @dfn{float} is a number stored in scientific |
10851 notation. The number of significant digits in the fractional part is | 10839 notation. The number of significant digits in the fractional part is |
10852 governed by the current floating precision (@pxref{Precision}). The | 10840 governed by the current floating precision (@pxref{Precision}). The |
10853 range of acceptable values is from | 10841 range of acceptable values is from |
10854 @texline @tmath{10^{-3999999}} | 10842 @texline @math{10^{-3999999}} |
10855 @infoline @expr{10^-3999999} | 10843 @infoline @expr{10^-3999999} |
10856 (inclusive) to | 10844 (inclusive) to |
10857 @texline @tmath{10^{4000000}} | 10845 @texline @math{10^{4000000}} |
10858 @infoline @expr{10^4000000} | 10846 @infoline @expr{10^4000000} |
10859 (exclusive), plus the corresponding negative values and zero. | 10847 (exclusive), plus the corresponding negative values and zero. |
10860 | 10848 |
10861 Calculations that would exceed the allowable range of values (such | 10849 Calculations that would exceed the allowable range of values (such |
10862 as @samp{exp(exp(20))}) are left in symbolic form by Calc. The | 10850 as @samp{exp(exp(20))}) are left in symbolic form by Calc. The |
10924 @var{imag} is the imaginary part, each of which may be any real number. | 10912 @var{imag} is the imaginary part, each of which may be any real number. |
10925 Rectangular complex numbers can also be displayed in @samp{@var{a}+@var{b}i} | 10913 Rectangular complex numbers can also be displayed in @samp{@var{a}+@var{b}i} |
10926 notation; @pxref{Complex Formats}. | 10914 notation; @pxref{Complex Formats}. |
10927 | 10915 |
10928 Polar complex numbers are displayed in the form | 10916 Polar complex numbers are displayed in the form |
10929 @texline `@t{(}@var{r}@t{;}@tmath{\theta}@t{)}' | 10917 @texline `@t{(}@var{r}@t{;}@math{\theta}@t{)}' |
10930 @infoline `@t{(}@var{r}@t{;}@var{theta}@t{)}' | 10918 @infoline `@t{(}@var{r}@t{;}@var{theta}@t{)}' |
10931 where @var{r} is the nonnegative magnitude and | 10919 where @var{r} is the nonnegative magnitude and |
10932 @texline @tmath{\theta} | 10920 @texline @math{\theta} |
10933 @infoline @var{theta} | 10921 @infoline @var{theta} |
10934 is the argument or phase angle. The range of | 10922 is the argument or phase angle. The range of |
10935 @texline @tmath{\theta} | 10923 @texline @math{\theta} |
10936 @infoline @var{theta} | 10924 @infoline @var{theta} |
10937 depends on the current angular mode (@pxref{Angular Modes}); it is | 10925 depends on the current angular mode (@pxref{Angular Modes}); it is |
10938 generally between @i{-180} and @i{+180} degrees or the equivalent range | 10926 generally between @mathit{-180} and @mathit{+180} degrees or the equivalent range |
10939 in radians. | 10927 in radians. |
10940 | 10928 |
10941 Complex numbers are entered in stages using incomplete objects. | 10929 Complex numbers are entered in stages using incomplete objects. |
10942 @xref{Incomplete Objects}. | 10930 @xref{Incomplete Objects}. |
10943 | 10931 |
10976 really mean is that @expr{1 / x}, as @expr{x} becomes larger and | 10964 really mean is that @expr{1 / x}, as @expr{x} becomes larger and |
10977 larger, becomes arbitrarily close to zero. So you can imagine | 10965 larger, becomes arbitrarily close to zero. So you can imagine |
10978 that if @expr{x} got ``all the way to infinity,'' then @expr{1 / x} | 10966 that if @expr{x} got ``all the way to infinity,'' then @expr{1 / x} |
10979 would go all the way to zero. Similarly, when they say that | 10967 would go all the way to zero. Similarly, when they say that |
10980 @samp{exp(inf) = inf}, they mean that | 10968 @samp{exp(inf) = inf}, they mean that |
10981 @texline @tmath{e^x} | 10969 @texline @math{e^x} |
10982 @infoline @expr{exp(x)} | 10970 @infoline @expr{exp(x)} |
10983 grows without bound as @expr{x} grows. The symbol @samp{-inf} likewise | 10971 grows without bound as @expr{x} grows. The symbol @samp{-inf} likewise |
10984 stands for an infinitely negative real value; for example, we say that | 10972 stands for an infinitely negative real value; for example, we say that |
10985 @samp{exp(-inf) = 0}. You can have an infinity pointing in any | 10973 @samp{exp(-inf) = 0}. You can have an infinity pointing in any |
10986 direction on the complex plane: @samp{sqrt(-inf) = i inf}. | 10974 direction on the complex plane: @samp{sqrt(-inf) = i inf}. |
11073 @starindex | 11061 @starindex |
11074 @end ignore | 11062 @end ignore |
11075 @tindex vec | 11063 @tindex vec |
11076 Algebraic functions for building vectors include @samp{vec(a, b, c)} | 11064 Algebraic functions for building vectors include @samp{vec(a, b, c)} |
11077 to build @samp{[a, b, c]}, @samp{cvec(a, n, m)} to build an | 11065 to build @samp{[a, b, c]}, @samp{cvec(a, n, m)} to build an |
11078 @texline @tmath{n\times m} | 11066 @texline @math{n\times m} |
11079 @infoline @var{n}x@var{m} | 11067 @infoline @var{n}x@var{m} |
11080 matrix of @samp{a}s, and @samp{index(n)} to build a vector of integers | 11068 matrix of @samp{a}s, and @samp{index(n)} to build a vector of integers |
11081 from 1 to @samp{n}. | 11069 from 1 to @samp{n}. |
11082 | 11070 |
11083 @node Strings, HMS Forms, Vectors and Matrices, Data Types | 11071 @node Strings, HMS Forms, Vectors and Matrices, Data Types |
11204 The @var{hours} value is an integer (or integer-valued float). | 11192 The @var{hours} value is an integer (or integer-valued float). |
11205 The @var{mins} value is an integer or integer-valued float between 0 and 59. | 11193 The @var{mins} value is an integer or integer-valued float between 0 and 59. |
11206 The @var{secs} value is a real number between 0 (inclusive) and 60 | 11194 The @var{secs} value is a real number between 0 (inclusive) and 60 |
11207 (exclusive). A positive HMS form is interpreted as @var{hours} + | 11195 (exclusive). A positive HMS form is interpreted as @var{hours} + |
11208 @var{mins}/60 + @var{secs}/3600. A negative HMS form is interpreted | 11196 @var{mins}/60 + @var{secs}/3600. A negative HMS form is interpreted |
11209 as @i{- @var{hours}} @i{-} @var{mins}/60 @i{-} @var{secs}/3600. | 11197 as @mathit{- @var{hours}} @mathit{-} @var{mins}/60 @mathit{-} @var{secs}/3600. |
11210 Display format for HMS forms is quite flexible. @xref{HMS Formats}. | 11198 Display format for HMS forms is quite flexible. @xref{HMS Formats}. |
11211 | 11199 |
11212 HMS forms can be added and subtracted. When they are added to numbers, | 11200 HMS forms can be added and subtracted. When they are added to numbers, |
11213 the numbers are interpreted according to the current angular mode. HMS | 11201 the numbers are interpreted according to the current angular mode. HMS |
11214 forms can also be multiplied and divided by real numbers. Dividing | 11202 forms can also be multiplied and divided by real numbers. Dividing |
11298 between, say, @samp{<12:00am Mon Jan 1, 1900>} and | 11286 between, say, @samp{<12:00am Mon Jan 1, 1900>} and |
11299 @samp{<12:00am Sat Jan 1, 2000>}.) | 11287 @samp{<12:00am Sat Jan 1, 2000>}.) |
11300 | 11288 |
11301 Calc uses the Julian calendar for all dates before the year 1752, | 11289 Calc uses the Julian calendar for all dates before the year 1752, |
11302 including dates BC when the Julian calendar technically had not | 11290 including dates BC when the Julian calendar technically had not |
11303 yet been invented. Thus the claim that day number @i{-10000} is | 11291 yet been invented. Thus the claim that day number @mathit{-10000} is |
11304 called ``August 16, 28 BC'' should be taken with a grain of salt. | 11292 called ``August 16, 28 BC'' should be taken with a grain of salt. |
11305 | 11293 |
11306 Please note that there is no ``year 0''; the day before | 11294 Please note that there is no ``year 0''; the day before |
11307 @samp{<Sat Jan 1, +1>} is @samp{<Fri Dec 31, -1>}. These are | 11295 @samp{<Sat Jan 1, +1>} is @samp{<Fri Dec 31, -1>}. These are |
11308 days 0 and @i{-1} respectively in Calc's internal numbering scheme. | 11296 days 0 and @mathit{-1} respectively in Calc's internal numbering scheme. |
11309 | 11297 |
11310 @cindex Julian day counting | 11298 @cindex Julian day counting |
11311 Another day counting system in common use is, confusingly, also | 11299 Another day counting system in common use is, confusingly, also |
11312 called ``Julian.'' It was invented in 1583 by Joseph Justus | 11300 called ``Julian.'' It was invented in 1583 by Joseph Justus |
11313 Scaliger, who named it in honor of his father Julius Caesar | 11301 Scaliger, who named it in honor of his father Julius Caesar |
11314 Scaliger. For obscure reasons he chose to start his day | 11302 Scaliger. For obscure reasons he chose to start his day |
11315 numbering on Jan 1, 4713 BC at noon, which in Calc's scheme | 11303 numbering on Jan 1, 4713 BC at noon, which in Calc's scheme |
11316 is @i{-1721423.5} (recall that Calc starts at midnight instead | 11304 is @mathit{-1721423.5} (recall that Calc starts at midnight instead |
11317 of noon). Thus to convert a Calc date code obtained by | 11305 of noon). Thus to convert a Calc date code obtained by |
11318 unpacking a date form into a Julian day number, simply add | 11306 unpacking a date form into a Julian day number, simply add |
11319 1721423.5. The Julian code for @samp{6:00am Jan 9, 1991} | 11307 1721423.5. The Julian code for @samp{6:00am Jan 9, 1991} |
11320 is 2448265.75. The built-in @kbd{t J} command performs | 11308 is 2448265.75. The built-in @kbd{t J} command performs |
11321 this conversion for you. | 11309 this conversion for you. |
11344 A @dfn{modulo form} is a real number which is taken modulo (i.e., within | 11332 A @dfn{modulo form} is a real number which is taken modulo (i.e., within |
11345 an integer multiple of) some value @var{M}. Arithmetic modulo @var{M} | 11333 an integer multiple of) some value @var{M}. Arithmetic modulo @var{M} |
11346 often arises in number theory. Modulo forms are written | 11334 often arises in number theory. Modulo forms are written |
11347 `@var{a} @t{mod} @var{M}', | 11335 `@var{a} @t{mod} @var{M}', |
11348 where @var{a} and @var{M} are real numbers or HMS forms, and | 11336 where @var{a} and @var{M} are real numbers or HMS forms, and |
11349 @texline @tmath{0 \le a < M}. | 11337 @texline @math{0 \le a < M}. |
11350 @infoline @expr{0 <= a < @var{M}}. | 11338 @infoline @expr{0 <= a < @var{M}}. |
11351 In many applications @expr{a} and @expr{M} will be | 11339 In many applications @expr{a} and @expr{M} will be |
11352 integers but this is not required. | 11340 integers but this is not required. |
11353 | 11341 |
11354 Modulo forms are not to be confused with the modulo operator @samp{%}. | 11342 Modulo forms are not to be confused with the modulo operator @samp{%}. |
11376 @expr{M} is non-prime), or if any of the arguments are non-integers, the | 11364 @expr{M} is non-prime), or if any of the arguments are non-integers, the |
11377 division is left in symbolic form. Other operations, such as square | 11365 division is left in symbolic form. Other operations, such as square |
11378 roots, are not yet supported for modulo forms. (Note that, although | 11366 roots, are not yet supported for modulo forms. (Note that, although |
11379 @w{`@t{(}@var{a} @t{mod} @var{M}@t{)^.5}'} will compute a ``modulo square root'' | 11367 @w{`@t{(}@var{a} @t{mod} @var{M}@t{)^.5}'} will compute a ``modulo square root'' |
11380 in the sense of reducing | 11368 in the sense of reducing |
11381 @texline @tmath{\sqrt a} | 11369 @texline @math{\sqrt a} |
11382 @infoline @expr{sqrt(a)} | 11370 @infoline @expr{sqrt(a)} |
11383 modulo @expr{M}, this is not a useful definition from the | 11371 modulo @expr{M}, this is not a useful definition from the |
11384 number-theoretical point of view.) | 11372 number-theoretical point of view.) |
11385 | 11373 |
11386 @ignore | 11374 @ignore |
11426 @noindent | 11414 @noindent |
11427 @cindex Error forms | 11415 @cindex Error forms |
11428 @cindex Standard deviations | 11416 @cindex Standard deviations |
11429 An @dfn{error form} is a number with an associated standard | 11417 An @dfn{error form} is a number with an associated standard |
11430 deviation, as in @samp{2.3 +/- 0.12}. The notation | 11418 deviation, as in @samp{2.3 +/- 0.12}. The notation |
11431 @texline `@var{x} @t{+/-} @tmath{\sigma}' | 11419 @texline `@var{x} @t{+/-} @math{\sigma}' |
11432 @infoline `@var{x} @t{+/-} sigma' | 11420 @infoline `@var{x} @t{+/-} sigma' |
11433 stands for an uncertain value which follows | 11421 stands for an uncertain value which follows |
11434 a normal or Gaussian distribution of mean @expr{x} and standard | 11422 a normal or Gaussian distribution of mean @expr{x} and standard |
11435 deviation or ``error'' | 11423 deviation or ``error'' |
11436 @texline @tmath{\sigma}. | 11424 @texline @math{\sigma}. |
11437 @infoline @expr{sigma}. | 11425 @infoline @expr{sigma}. |
11438 Both the mean and the error can be either numbers or | 11426 Both the mean and the error can be either numbers or |
11439 formulas. Generally these are real numbers but the mean may also be | 11427 formulas. Generally these are real numbers but the mean may also be |
11440 complex. If the error is negative or complex, it is changed to its | 11428 complex. If the error is negative or complex, it is changed to its |
11441 absolute value. An error form with zero error is converted to a | 11429 absolute value. An error form with zero error is converted to a |
11442 regular number by the Calculator. | 11430 regular number by the Calculator. |
11443 | 11431 |
11444 All arithmetic and transcendental functions accept error forms as input. | 11432 All arithmetic and transcendental functions accept error forms as input. |
11445 Operations on the mean-value part work just like operations on regular | 11433 Operations on the mean-value part work just like operations on regular |
11446 numbers. The error part for any function @expr{f(x)} (such as | 11434 numbers. The error part for any function @expr{f(x)} (such as |
11447 @texline @tmath{\sin x} | 11435 @texline @math{\sin x} |
11448 @infoline @expr{sin(x)}) | 11436 @infoline @expr{sin(x)}) |
11449 is defined by the error of @expr{x} times the derivative of @expr{f} | 11437 is defined by the error of @expr{x} times the derivative of @expr{f} |
11450 evaluated at the mean value of @expr{x}. For a two-argument function | 11438 evaluated at the mean value of @expr{x}. For a two-argument function |
11451 @expr{f(x,y)} (such as addition) the error is the square root of the sum | 11439 @expr{f(x,y)} (such as addition) the error is the square root of the sum |
11452 of the squares of the errors due to @expr{x} and @expr{y}. | 11440 of the squares of the errors due to @expr{x} and @expr{y}. |
11473 | 11461 |
11474 Consult a good text on error analysis for a discussion of the proper use | 11462 Consult a good text on error analysis for a discussion of the proper use |
11475 of standard deviations. Actual errors often are neither Gaussian-distributed | 11463 of standard deviations. Actual errors often are neither Gaussian-distributed |
11476 nor uncorrelated, and the above formulas are valid only when errors | 11464 nor uncorrelated, and the above formulas are valid only when errors |
11477 are small. As an example, the error arising from | 11465 are small. As an example, the error arising from |
11478 @texline `@t{sin(}@var{x} @t{+/-} @tmath{\sigma}@t{)}' | 11466 @texline `@t{sin(}@var{x} @t{+/-} @math{\sigma}@t{)}' |
11479 @infoline `@t{sin(}@var{x} @t{+/-} @var{sigma}@t{)}' | 11467 @infoline `@t{sin(}@var{x} @t{+/-} @var{sigma}@t{)}' |
11480 is | 11468 is |
11481 @texline `@tmath{\sigma} @t{abs(cos(}@var{x}@t{))}'. | 11469 @texline `@math{\sigma} @t{abs(cos(}@var{x}@t{))}'. |
11482 @infoline `@var{sigma} @t{abs(cos(}@var{x}@t{))}'. | 11470 @infoline `@var{sigma} @t{abs(cos(}@var{x}@t{))}'. |
11483 When @expr{x} is close to zero, | 11471 When @expr{x} is close to zero, |
11484 @texline @tmath{\cos x} | 11472 @texline @math{\cos x} |
11485 @infoline @expr{cos(x)} | 11473 @infoline @expr{cos(x)} |
11486 is close to one so the error in the sine is close to | 11474 is close to one so the error in the sine is close to |
11487 @texline @tmath{\sigma}; | 11475 @texline @math{\sigma}; |
11488 @infoline @expr{sigma}; | 11476 @infoline @expr{sigma}; |
11489 this makes sense, since | 11477 this makes sense, since |
11490 @texline @tmath{\sin x} | 11478 @texline @math{\sin x} |
11491 @infoline @expr{sin(x)} | 11479 @infoline @expr{sin(x)} |
11492 is approximately @expr{x} near zero, so a given error in @expr{x} will | 11480 is approximately @expr{x} near zero, so a given error in @expr{x} will |
11493 produce about the same error in the sine. Likewise, near 90 degrees | 11481 produce about the same error in the sine. Likewise, near 90 degrees |
11494 @texline @tmath{\cos x} | 11482 @texline @math{\cos x} |
11495 @infoline @expr{cos(x)} | 11483 @infoline @expr{cos(x)} |
11496 is nearly zero and so the computed error is | 11484 is nearly zero and so the computed error is |
11497 small: The sine curve is nearly flat in that region, so an error in @expr{x} | 11485 small: The sine curve is nearly flat in that region, so an error in @expr{x} |
11498 has relatively little effect on the value of | 11486 has relatively little effect on the value of |
11499 @texline @tmath{\sin x}. | 11487 @texline @math{\sin x}. |
11500 @infoline @expr{sin(x)}. | 11488 @infoline @expr{sin(x)}. |
11501 However, consider @samp{sin(90 +/- 1000)}. The cosine of 90 is zero, so | 11489 However, consider @samp{sin(90 +/- 1000)}. The cosine of 90 is zero, so |
11502 Calc will report zero error! We get an obviously wrong result because | 11490 Calc will report zero error! We get an obviously wrong result because |
11503 we have violated the small-error approximation underlying the error | 11491 we have violated the small-error approximation underlying the error |
11504 analysis. If the error in @expr{x} had been small, the error in | 11492 analysis. If the error in @expr{x} had been small, the error in |
11505 @texline @tmath{\sin x} | 11493 @texline @math{\sin x} |
11506 @infoline @expr{sin(x)} | 11494 @infoline @expr{sin(x)} |
11507 would indeed have been negligible. | 11495 would indeed have been negligible. |
11508 | 11496 |
11509 @ignore | 11497 @ignore |
11510 @mindex p | 11498 @mindex p |
11609 @samp{1 / (-2 .. 2) = [-inf .. inf]}. | 11597 @samp{1 / (-2 .. 2) = [-inf .. inf]}. |
11610 | 11598 |
11611 While it may seem that intervals and error forms are similar, they are | 11599 While it may seem that intervals and error forms are similar, they are |
11612 based on entirely different concepts of inexact quantities. An error | 11600 based on entirely different concepts of inexact quantities. An error |
11613 form | 11601 form |
11614 @texline `@var{x} @t{+/-} @tmath{\sigma}' | 11602 @texline `@var{x} @t{+/-} @math{\sigma}' |
11615 @infoline `@var{x} @t{+/-} @var{sigma}' | 11603 @infoline `@var{x} @t{+/-} @var{sigma}' |
11616 means a variable is random, and its value could | 11604 means a variable is random, and its value could |
11617 be anything but is ``probably'' within one | 11605 be anything but is ``probably'' within one |
11618 @texline @tmath{\sigma} | 11606 @texline @math{\sigma} |
11619 @infoline @var{sigma} | 11607 @infoline @var{sigma} |
11620 of the mean value @expr{x}. An interval | 11608 of the mean value @expr{x}. An interval |
11621 `@t{[}@var{a} @t{..@:} @var{b}@t{]}' means a | 11609 `@t{[}@var{a} @t{..@:} @var{b}@t{]}' means a |
11622 variable's value is unknown, but guaranteed to lie in the specified | 11610 variable's value is unknown, but guaranteed to lie in the specified |
11623 range. Error forms are statistical or ``average case'' approximations; | 11611 range. Error forms are statistical or ``average case'' approximations; |
11847 | 11835 |
11848 @samp{=>} [@code{evalto}]. | 11836 @samp{=>} [@code{evalto}]. |
11849 | 11837 |
11850 Note that, unlike in usual computer notation, multiplication binds more | 11838 Note that, unlike in usual computer notation, multiplication binds more |
11851 strongly than division: @samp{a*b/c*d} is equivalent to | 11839 strongly than division: @samp{a*b/c*d} is equivalent to |
11852 @texline @tmath{a b \over c d}. | 11840 @texline @math{a b \over c d}. |
11853 @infoline @expr{(a*b)/(c*d)}. | 11841 @infoline @expr{(a*b)/(c*d)}. |
11854 | 11842 |
11855 @cindex Multiplication, implicit | 11843 @cindex Multiplication, implicit |
11856 @cindex Implicit multiplication | 11844 @cindex Implicit multiplication |
11857 The multiplication sign @samp{*} may be omitted in many cases. In particular, | 11845 The multiplication sign @samp{*} may be omitted in many cases. In particular, |
12045 element down to level @var{n}, making room for it by pulling all the | 12033 element down to level @var{n}, making room for it by pulling all the |
12046 intervening stack elements toward the top. @kbd{M-@key{TAB}} moves the | 12034 intervening stack elements toward the top. @kbd{M-@key{TAB}} moves the |
12047 element at level @var{n} up to the top. (Compare with @key{LFD}, | 12035 element at level @var{n} up to the top. (Compare with @key{LFD}, |
12048 which copies instead of moving the element in level @var{n}.) | 12036 which copies instead of moving the element in level @var{n}.) |
12049 | 12037 |
12050 With a negative argument @i{-@var{n}}, @key{TAB} rotates the stack | 12038 With a negative argument @mathit{-@var{n}}, @key{TAB} rotates the stack |
12051 to move the object in level @var{n} to the deepest place in the | 12039 to move the object in level @var{n} to the deepest place in the |
12052 stack, and the object in level @i{@var{n}+1} to the top. @kbd{M-@key{TAB}} | 12040 stack, and the object in level @mathit{@var{n}+1} to the top. @kbd{M-@key{TAB}} |
12053 rotates the deepest stack element to be in level @i{n}, also | 12041 rotates the deepest stack element to be in level @mathit{n}, also |
12054 putting the top stack element in level @i{@var{n}+1}. | 12042 putting the top stack element in level @mathit{@var{n}+1}. |
12055 | 12043 |
12056 @xref{Selecting Subformulas}, for a way to apply these commands to | 12044 @xref{Selecting Subformulas}, for a way to apply these commands to |
12057 any portion of a vector or formula on the stack. | 12045 any portion of a vector or formula on the stack. |
12058 | 12046 |
12059 @node Editing Stack Entries, Trail Commands, Stack Manipulation, Stack and Trail | 12047 @node Editing Stack Entries, Trail Commands, Stack Manipulation, Stack and Trail |
12344 If the file name you give contains the string @samp{.emacs} anywhere | 12332 If the file name you give contains the string @samp{.emacs} anywhere |
12345 inside it, @kbd{m F} will not automatically load the new file. This | 12333 inside it, @kbd{m F} will not automatically load the new file. This |
12346 is because you are presumably switching to your @file{~/.emacs} file, | 12334 is because you are presumably switching to your @file{~/.emacs} file, |
12347 which may contain other things you don't want to reread. You can give | 12335 which may contain other things you don't want to reread. You can give |
12348 a numeric prefix argument of 1 to @kbd{m F} to force it to read the | 12336 a numeric prefix argument of 1 to @kbd{m F} to force it to read the |
12349 file no matter what its name. Conversely, an argument of @i{-1} tells | 12337 file no matter what its name. Conversely, an argument of @mathit{-1} tells |
12350 @kbd{m F} @emph{not} to read the new file. An argument of 2 or @i{-2} | 12338 @kbd{m F} @emph{not} to read the new file. An argument of 2 or @mathit{-2} |
12351 tells @kbd{m F} not to reset the modes to their defaults beforehand, | 12339 tells @kbd{m F} not to reset the modes to their defaults beforehand, |
12352 which is useful if you intend your new file to have a variant of the | 12340 which is useful if you intend your new file to have a variant of the |
12353 modes present in the file you were using before. | 12341 modes present in the file you were using before. |
12354 | 12342 |
12355 @kindex m x | 12343 @kindex m x |
12450 Likewise, the @kbd{H} key (@code{calc-hyperbolic}) sets or clears the | 12438 Likewise, the @kbd{H} key (@code{calc-hyperbolic}) sets or clears the |
12451 Hyperbolic Flag, which transforms @code{calc-sin} into @code{calc-sinh}. | 12439 Hyperbolic Flag, which transforms @code{calc-sin} into @code{calc-sinh}. |
12452 If both of these flags are set at once, the effect will be | 12440 If both of these flags are set at once, the effect will be |
12453 @code{calc-arcsinh}. (The Hyperbolic flag is also used by some | 12441 @code{calc-arcsinh}. (The Hyperbolic flag is also used by some |
12454 non-trigonometric commands; for example @kbd{H L} computes a base-10, | 12442 non-trigonometric commands; for example @kbd{H L} computes a base-10, |
12455 instead of base-@i{e}, logarithm.) | 12443 instead of base-@mathit{e}, logarithm.) |
12456 | 12444 |
12457 Command names like @code{calc-arcsin} are provided for completeness, and | 12445 Command names like @code{calc-arcsin} are provided for completeness, and |
12458 may be executed with @kbd{x} or @kbd{M-x}. Their effect is simply to | 12446 may be executed with @kbd{x} or @kbd{M-x}. Their effect is simply to |
12459 toggle the Inverse and/or Hyperbolic flags and then execute the | 12447 toggle the Inverse and/or Hyperbolic flags and then execute the |
12460 corresponding base command (@code{calc-sin} in this case). | 12448 corresponding base command (@code{calc-sin} in this case). |
12594 The @kbd{m i} command with a numeric prefix argument of zero, | 12582 The @kbd{m i} command with a numeric prefix argument of zero, |
12595 i.e., @kbd{C-u 0 m i}, turns on a ``positive infinite mode'' in | 12583 i.e., @kbd{C-u 0 m i}, turns on a ``positive infinite mode'' in |
12596 which zero is treated as positive instead of being directionless. | 12584 which zero is treated as positive instead of being directionless. |
12597 Thus, @samp{1 / 0 = inf} and @samp{-1 / 0 = -inf} in this mode. | 12585 Thus, @samp{1 / 0 = inf} and @samp{-1 / 0 = -inf} in this mode. |
12598 Note that zero never actually has a sign in Calc; there are no | 12586 Note that zero never actually has a sign in Calc; there are no |
12599 separate representations for @i{+0} and @i{-0}. Positive | 12587 separate representations for @mathit{+0} and @mathit{-0}. Positive |
12600 infinite mode merely changes the interpretation given to the | 12588 infinite mode merely changes the interpretation given to the |
12601 single symbol, @samp{0}. One consequence of this is that, while | 12589 single symbol, @samp{0}. One consequence of this is that, while |
12602 you might expect @samp{1 / -0 = -inf}, actually @samp{1 / -0} | 12590 you might expect @samp{1 / -0 = -inf}, actually @samp{1 / -0} |
12603 is equivalent to @samp{1 / 0}, which is equal to positive @code{inf}. | 12591 is equivalent to @samp{1 / 0}, which is equal to positive @code{inf}. |
12604 | 12592 |
12985 @end table | 12973 @end table |
12986 | 12974 |
12987 Calc uses this information to determine when certain simplifications | 12975 Calc uses this information to determine when certain simplifications |
12988 of formulas are safe. For example, @samp{(x^y)^z} cannot be | 12976 of formulas are safe. For example, @samp{(x^y)^z} cannot be |
12989 simplified to @samp{x^(y z)} in general; for example, | 12977 simplified to @samp{x^(y z)} in general; for example, |
12990 @samp{((-3)^2)^1:2} is 3, but @samp{(-3)^(2*1:2) = (-3)^1} is @i{-3}. | 12978 @samp{((-3)^2)^1:2} is 3, but @samp{(-3)^(2*1:2) = (-3)^1} is @mathit{-3}. |
12991 However, this simplification @emph{is} safe if @code{z} is known | 12979 However, this simplification @emph{is} safe if @code{z} is known |
12992 to be an integer, or if @code{x} is known to be a nonnegative | 12980 to be an integer, or if @code{x} is known to be a nonnegative |
12993 real number. If you have given declarations that allow Calc to | 12981 real number. If you have given declarations that allow Calc to |
12994 deduce either of these facts, Calc will perform this simplification | 12982 deduce either of these facts, Calc will perform this simplification |
12995 of the formula. | 12983 of the formula. |
13098 @item const | 13086 @item const |
13099 The value is a constant with respect to other variables. | 13087 The value is a constant with respect to other variables. |
13100 @end table | 13088 @end table |
13101 | 13089 |
13102 Calc does not check the declarations for a variable when you store | 13090 Calc does not check the declarations for a variable when you store |
13103 a value in it. However, storing @i{-3.5} in a variable that has | 13091 a value in it. However, storing @mathit{-3.5} in a variable that has |
13104 been declared @code{pos}, @code{int}, or @code{matrix} may have | 13092 been declared @code{pos}, @code{int}, or @code{matrix} may have |
13105 unexpected effects; Calc may evaluate @samp{sqrt(x^2)} to @expr{3.5} | 13093 unexpected effects; Calc may evaluate @samp{sqrt(x^2)} to @expr{3.5} |
13106 if it substitutes the value first, or to @expr{-3.5} if @code{x} | 13094 if it substitutes the value first, or to @expr{-3.5} if @code{x} |
13107 was declared @code{pos} and the formula @samp{sqrt(x^2)} is | 13095 was declared @code{pos} and the formula @samp{sqrt(x^2)} is |
13108 simplified to @samp{x} before the value is substituted. Before | 13096 simplified to @samp{x} before the value is substituted. Before |
13333 represent the integer and no more. The @kbd{d z} (@code{calc-leading-zeros}) | 13321 represent the integer and no more. The @kbd{d z} (@code{calc-leading-zeros}) |
13334 command causes integers to be padded out with leading zeros according to the | 13322 command causes integers to be padded out with leading zeros according to the |
13335 current binary word size. (@xref{Binary Functions}, for a discussion of | 13323 current binary word size. (@xref{Binary Functions}, for a discussion of |
13336 word size.) If the absolute value of the word size is @expr{w}, all integers | 13324 word size.) If the absolute value of the word size is @expr{w}, all integers |
13337 are displayed with at least enough digits to represent | 13325 are displayed with at least enough digits to represent |
13338 @texline @tmath{2^w-1} | 13326 @texline @math{2^w-1} |
13339 @infoline @expr{(2^w)-1} | 13327 @infoline @expr{(2^w)-1} |
13340 in the current radix. (Larger integers will still be displayed in their | 13328 in the current radix. (Larger integers will still be displayed in their |
13341 entirety.) | 13329 entirety.) |
13342 | 13330 |
13343 @node Grouping Digits, Float Formats, Radix Modes, Display Modes | 13331 @node Grouping Digits, Float Formats, Radix Modes, Display Modes |
14234 by the arguments in parentheses. However, functions for which @TeX{} has | 14222 by the arguments in parentheses. However, functions for which @TeX{} has |
14235 special names (like @code{\sin}) will use curly braces instead of | 14223 special names (like @code{\sin}) will use curly braces instead of |
14236 parentheses for very simple arguments. During input, curly braces and | 14224 parentheses for very simple arguments. During input, curly braces and |
14237 parentheses work equally well for grouping, but when the document is | 14225 parentheses work equally well for grouping, but when the document is |
14238 formatted the curly braces will be invisible. Thus the printed result is | 14226 formatted the curly braces will be invisible. Thus the printed result is |
14239 @texline @tmath{\sin{2 x}} | 14227 @texline @math{\sin{2 x}} |
14240 @infoline @expr{sin 2x} | 14228 @infoline @expr{sin 2x} |
14241 but | 14229 but |
14242 @texline @tmath{\sin(2 + x)}. | 14230 @texline @math{\sin(2 + x)}. |
14243 @infoline @expr{sin(2 + x)}. | 14231 @infoline @expr{sin(2 + x)}. |
14244 | 14232 |
14245 Function and variable names not treated specially by @TeX{} are simply | 14233 Function and variable names not treated specially by @TeX{} are simply |
14246 written out as-is, which will cause them to come out in italic letters | 14234 written out as-is, which will cause them to come out in italic letters |
14247 in the printed document. If you invoke @kbd{d T} with a positive numeric | 14235 in the printed document. If you invoke @kbd{d T} with a positive numeric |
15731 @item | 15719 @item |
15732 Polar mode. Value is 0 (rectangular) or 1 (polar); default is 0. | 15720 Polar mode. Value is 0 (rectangular) or 1 (polar); default is 0. |
15733 Command is @kbd{m p}. | 15721 Command is @kbd{m p}. |
15734 | 15722 |
15735 @item | 15723 @item |
15736 Matrix/scalar mode. Default value is @i{-1}. Value is 0 for scalar | 15724 Matrix/scalar mode. Default value is @mathit{-1}. Value is 0 for scalar |
15737 mode, @i{-2} for matrix mode, or @var{N} for | 15725 mode, @mathit{-2} for matrix mode, or @var{N} for |
15738 @texline @tmath{N\times N} | 15726 @texline @math{N\times N} |
15739 @infoline @var{N}x@var{N} | 15727 @infoline @var{N}x@var{N} |
15740 matrix mode. Command is @kbd{m v}. | 15728 matrix mode. Command is @kbd{m v}. |
15741 | 15729 |
15742 @item | 15730 @item |
15743 Simplification mode. Default is 1. Value is @i{-1} for off (@kbd{m O}), | 15731 Simplification mode. Default is 1. Value is @mathit{-1} for off (@kbd{m O}), |
15744 0 for @kbd{m N}, 2 for @kbd{m B}, 3 for @kbd{m A}, 4 for @kbd{m E}, | 15732 0 for @kbd{m N}, 2 for @kbd{m B}, 3 for @kbd{m A}, 4 for @kbd{m E}, |
15745 or 5 for @w{@kbd{m U}}. The @kbd{m D} command accepts these prefixes. | 15733 or 5 for @w{@kbd{m U}}. The @kbd{m D} command accepts these prefixes. |
15746 | 15734 |
15747 @item | 15735 @item |
15748 Infinite mode. Default is @i{-1} (off). Value is 1 if the mode is on, | 15736 Infinite mode. Default is @mathit{-1} (off). Value is 1 if the mode is on, |
15749 or 0 if the mode is on with positive zeros. Command is @kbd{m i}. | 15737 or 0 if the mode is on with positive zeros. Command is @kbd{m i}. |
15750 @end enumerate | 15738 @end enumerate |
15751 | 15739 |
15752 For example, the sequence @kbd{M-1 m g @key{RET} 2 + ~ p} increases the | 15740 For example, the sequence @kbd{M-1 m g @key{RET} 2 + ~ p} increases the |
15753 precision by two, leaving a copy of the old precision on the stack. | 15741 precision by two, leaving a copy of the old precision on the stack. |
16084 @mindex @null | 16072 @mindex @null |
16085 @end ignore | 16073 @end ignore |
16086 @tindex - | 16074 @tindex - |
16087 The @kbd{-} (@code{calc-minus}) command subtracts two values. The top | 16075 The @kbd{-} (@code{calc-minus}) command subtracts two values. The top |
16088 number on the stack is subtracted from the one behind it, so that the | 16076 number on the stack is subtracted from the one behind it, so that the |
16089 computation @kbd{5 @key{RET} 2 -} produces 3, not @i{-3}. All options | 16077 computation @kbd{5 @key{RET} 2 -} produces 3, not @mathit{-3}. All options |
16090 available for @kbd{+} are available for @kbd{-} as well. | 16078 available for @kbd{+} are available for @kbd{-} as well. |
16091 | 16079 |
16092 @kindex * | 16080 @kindex * |
16093 @pindex calc-times | 16081 @pindex calc-times |
16094 @ignore | 16082 @ignore |
16228 | 16216 |
16229 @kindex f s | 16217 @kindex f s |
16230 @pindex calc-sign | 16218 @pindex calc-sign |
16231 @tindex sign | 16219 @tindex sign |
16232 The @kbd{f s} (@code{calc-sign}) [@code{sign}] command returns 1 if its | 16220 The @kbd{f s} (@code{calc-sign}) [@code{sign}] command returns 1 if its |
16233 argument is positive, @i{-1} if its argument is negative, or 0 if its | 16221 argument is positive, @mathit{-1} if its argument is negative, or 0 if its |
16234 argument is zero. In algebraic form, you can also write @samp{sign(a,x)} | 16222 argument is zero. In algebraic form, you can also write @samp{sign(a,x)} |
16235 which evaluates to @samp{x * sign(a)}, i.e., either @samp{x}, @samp{-x}, or | 16223 which evaluates to @samp{x * sign(a)}, i.e., either @samp{x}, @samp{-x}, or |
16236 zero depending on the sign of @samp{a}. | 16224 zero depending on the sign of @samp{a}. |
16237 | 16225 |
16238 @kindex & | 16226 @kindex & |
16291 @tindex xpon | 16279 @tindex xpon |
16292 The @kbd{f M} (@code{calc-mant-part}) [@code{mant}] function extracts | 16280 The @kbd{f M} (@code{calc-mant-part}) [@code{mant}] function extracts |
16293 the ``mantissa'' part @expr{m} of its floating-point argument; @kbd{f X} | 16281 the ``mantissa'' part @expr{m} of its floating-point argument; @kbd{f X} |
16294 (@code{calc-xpon-part}) [@code{xpon}] extracts the ``exponent'' part | 16282 (@code{calc-xpon-part}) [@code{xpon}] extracts the ``exponent'' part |
16295 @expr{e}. The original number is equal to | 16283 @expr{e}. The original number is equal to |
16296 @texline @tmath{m \times 10^e}, | 16284 @texline @math{m \times 10^e}, |
16297 @infoline @expr{m * 10^e}, | 16285 @infoline @expr{m * 10^e}, |
16298 where @expr{m} is in the interval @samp{[1.0 ..@: 10.0)} except that | 16286 where @expr{m} is in the interval @samp{[1.0 ..@: 10.0)} except that |
16299 @expr{m=e=0} if the original number is zero. For integers | 16287 @expr{m=e=0} if the original number is zero. For integers |
16300 and fractions, @code{mant} returns the number unchanged and @code{xpon} | 16288 and fractions, @code{mant} returns the number unchanged and @code{xpon} |
16301 returns zero. The @kbd{v u} (@code{calc-unpack}) command can also be | 16289 returns zero. The @kbd{v u} (@code{calc-unpack}) command can also be |
16324 floating-point numbers, the change is by one unit in the last place. | 16312 floating-point numbers, the change is by one unit in the last place. |
16325 For example, incrementing @samp{12.3456} when the current precision | 16313 For example, incrementing @samp{12.3456} when the current precision |
16326 is 6 digits yields @samp{12.3457}. If the current precision had been | 16314 is 6 digits yields @samp{12.3457}. If the current precision had been |
16327 8 digits, the result would have been @samp{12.345601}. Incrementing | 16315 8 digits, the result would have been @samp{12.345601}. Incrementing |
16328 @samp{0.0} produces | 16316 @samp{0.0} produces |
16329 @texline @tmath{10^{-p}}, | 16317 @texline @math{10^{-p}}, |
16330 @infoline @expr{10^-p}, | 16318 @infoline @expr{10^-p}, |
16331 where @expr{p} is the current | 16319 where @expr{p} is the current |
16332 precision. These operations are defined only on integers and floats. | 16320 precision. These operations are defined only on integers and floats. |
16333 With numeric prefix arguments, they change the number by @expr{n} units. | 16321 With numeric prefix arguments, they change the number by @expr{n} units. |
16334 | 16322 |
16365 @end ignore | 16353 @end ignore |
16366 @kindex H F | 16354 @kindex H F |
16367 The @kbd{F} (@code{calc-floor}) [@code{floor} or @code{ffloor}] command | 16355 The @kbd{F} (@code{calc-floor}) [@code{floor} or @code{ffloor}] command |
16368 truncates a real number to the next lower integer, i.e., toward minus | 16356 truncates a real number to the next lower integer, i.e., toward minus |
16369 infinity. Thus @kbd{3.6 F} produces 3, but @kbd{_3.6 F} produces | 16357 infinity. Thus @kbd{3.6 F} produces 3, but @kbd{_3.6 F} produces |
16370 @i{-4}. | 16358 @mathit{-4}. |
16371 | 16359 |
16372 @kindex I F | 16360 @kindex I F |
16373 @pindex calc-ceiling | 16361 @pindex calc-ceiling |
16374 @tindex ceil | 16362 @tindex ceil |
16375 @tindex fceil | 16363 @tindex fceil |
16377 @mindex @null | 16365 @mindex @null |
16378 @end ignore | 16366 @end ignore |
16379 @kindex H I F | 16367 @kindex H I F |
16380 The @kbd{I F} (@code{calc-ceiling}) [@code{ceil} or @code{fceil}] | 16368 The @kbd{I F} (@code{calc-ceiling}) [@code{ceil} or @code{fceil}] |
16381 command truncates toward positive infinity. Thus @kbd{3.6 I F} produces | 16369 command truncates toward positive infinity. Thus @kbd{3.6 I F} produces |
16382 4, and @kbd{_3.6 I F} produces @i{-3}. | 16370 4, and @kbd{_3.6 I F} produces @mathit{-3}. |
16383 | 16371 |
16384 @kindex R | 16372 @kindex R |
16385 @pindex calc-round | 16373 @pindex calc-round |
16386 @tindex round | 16374 @tindex round |
16387 @tindex fround | 16375 @tindex fround |
16391 @kindex H R | 16379 @kindex H R |
16392 The @kbd{R} (@code{calc-round}) [@code{round} or @code{fround}] command | 16380 The @kbd{R} (@code{calc-round}) [@code{round} or @code{fround}] command |
16393 rounds to the nearest integer. When the fractional part is .5 exactly, | 16381 rounds to the nearest integer. When the fractional part is .5 exactly, |
16394 this command rounds away from zero. (All other rounding in the | 16382 this command rounds away from zero. (All other rounding in the |
16395 Calculator uses this convention as well.) Thus @kbd{3.5 R} produces 4 | 16383 Calculator uses this convention as well.) Thus @kbd{3.5 R} produces 4 |
16396 but @kbd{3.4 R} produces 3; @kbd{_3.5 R} produces @i{-4}. | 16384 but @kbd{3.4 R} produces 3; @kbd{_3.5 R} produces @mathit{-4}. |
16397 | 16385 |
16398 @kindex I R | 16386 @kindex I R |
16399 @pindex calc-trunc | 16387 @pindex calc-trunc |
16400 @tindex trunc | 16388 @tindex trunc |
16401 @tindex ftrunc | 16389 @tindex ftrunc |
16404 @end ignore | 16392 @end ignore |
16405 @kindex H I R | 16393 @kindex H I R |
16406 The @kbd{I R} (@code{calc-trunc}) [@code{trunc} or @code{ftrunc}] | 16394 The @kbd{I R} (@code{calc-trunc}) [@code{trunc} or @code{ftrunc}] |
16407 command truncates toward zero. In other words, it ``chops off'' | 16395 command truncates toward zero. In other words, it ``chops off'' |
16408 everything after the decimal point. Thus @kbd{3.6 I R} produces 3 and | 16396 everything after the decimal point. Thus @kbd{3.6 I R} produces 3 and |
16409 @kbd{_3.6 I R} produces @i{-3}. | 16397 @kbd{_3.6 I R} produces @mathit{-3}. |
16410 | 16398 |
16411 These functions may not be applied meaningfully to error forms, but they | 16399 These functions may not be applied meaningfully to error forms, but they |
16412 do work for intervals. As a convenience, applying @code{floor} to a | 16400 do work for intervals. As a convenience, applying @code{floor} to a |
16413 modulo form floors the value part of the form. Applied to a vector, | 16401 modulo form floors the value part of the form. Applied to a vector, |
16414 these functions operate on all elements of the vector one by one. | 16402 these functions operate on all elements of the vector one by one. |
16482 @pindex calc-argument | 16470 @pindex calc-argument |
16483 @tindex arg | 16471 @tindex arg |
16484 The @kbd{G} (@code{calc-argument}) [@code{arg}] command computes the | 16472 The @kbd{G} (@code{calc-argument}) [@code{arg}] command computes the |
16485 ``argument'' or polar angle of a complex number. For a number in polar | 16473 ``argument'' or polar angle of a complex number. For a number in polar |
16486 notation, this is simply the second component of the pair | 16474 notation, this is simply the second component of the pair |
16487 @texline `@t{(}@var{r}@t{;}@tmath{\theta}@t{)}'. | 16475 @texline `@t{(}@var{r}@t{;}@math{\theta}@t{)}'. |
16488 @infoline `@t{(}@var{r}@t{;}@var{theta}@t{)}'. | 16476 @infoline `@t{(}@var{r}@t{;}@var{theta}@t{)}'. |
16489 The result is expressed according to the current angular mode and will | 16477 The result is expressed according to the current angular mode and will |
16490 be in the range @i{-180} degrees (exclusive) to @i{+180} degrees | 16478 be in the range @mathit{-180} degrees (exclusive) to @mathit{+180} degrees |
16491 (inclusive), or the equivalent range in radians. | 16479 (inclusive), or the equivalent range in radians. |
16492 | 16480 |
16493 @pindex calc-imaginary | 16481 @pindex calc-imaginary |
16494 The @code{calc-imaginary} command multiplies the number on the | 16482 The @code{calc-imaginary} command multiplies the number on the |
16495 top of the stack by the imaginary number @expr{i = (0,1)}. This | 16483 top of the stack by the imaginary number @expr{i = (0,1)}. This |
16516 @end ignore | 16504 @end ignore |
16517 @kindex v p (complex) | 16505 @kindex v p (complex) |
16518 @pindex calc-pack | 16506 @pindex calc-pack |
16519 The @kbd{v p} (@code{calc-pack}) command can pack the top two numbers on | 16507 The @kbd{v p} (@code{calc-pack}) command can pack the top two numbers on |
16520 the stack into a composite object such as a complex number. With | 16508 the stack into a composite object such as a complex number. With |
16521 a prefix argument of @i{-1}, it produces a rectangular complex number; | 16509 a prefix argument of @mathit{-1}, it produces a rectangular complex number; |
16522 with an argument of @i{-2}, it produces a polar complex number. | 16510 with an argument of @mathit{-2}, it produces a polar complex number. |
16523 (Also, @pxref{Building Vectors}.) | 16511 (Also, @pxref{Building Vectors}.) |
16524 | 16512 |
16525 @ignore | 16513 @ignore |
16526 @mindex v u | 16514 @mindex v u |
16527 @end ignore | 16515 @end ignore |
16641 @pindex calc-clean | 16629 @pindex calc-clean |
16642 @tindex pclean | 16630 @tindex pclean |
16643 The @kbd{c c} (@code{calc-clean}) [@code{pclean}] command ``cleans'' the | 16631 The @kbd{c c} (@code{calc-clean}) [@code{pclean}] command ``cleans'' the |
16644 number on the top of the stack. Floating point numbers are re-rounded | 16632 number on the top of the stack. Floating point numbers are re-rounded |
16645 according to the current precision. Polar numbers whose angular | 16633 according to the current precision. Polar numbers whose angular |
16646 components have strayed from the @i{-180} to @i{+180} degree range | 16634 components have strayed from the @mathit{-180} to @mathit{+180} degree range |
16647 are normalized. (Note that results will be undesirable if the current | 16635 are normalized. (Note that results will be undesirable if the current |
16648 angular mode is different from the one under which the number was | 16636 angular mode is different from the one under which the number was |
16649 produced!) Integers and fractions are generally unaffected by this | 16637 produced!) Integers and fractions are generally unaffected by this |
16650 operation. Vectors and formulas are cleaned by cleaning each component | 16638 operation. Vectors and formulas are cleaned by cleaning each component |
16651 number (i.e., pervasively). | 16639 number (i.e., pervasively). |
16897 the year specified by the input. The month, day, and time | 16885 the year specified by the input. The month, day, and time |
16898 of the input date form are lost. With a numeric prefix argument | 16886 of the input date form are lost. With a numeric prefix argument |
16899 @var{n} in the range from 1 to 366, @kbd{t Y} computes the | 16887 @var{n} in the range from 1 to 366, @kbd{t Y} computes the |
16900 @var{n}th day of the year (366 is treated as 365 in non-leap | 16888 @var{n}th day of the year (366 is treated as 365 in non-leap |
16901 years). A prefix argument of 0 computes the last day of the | 16889 years). A prefix argument of 0 computes the last day of the |
16902 year (December 31). A negative prefix argument from @i{-1} to | 16890 year (December 31). A negative prefix argument from @mathit{-1} to |
16903 @i{-12} computes the first day of the @var{n}th month of the year. | 16891 @mathit{-12} computes the first day of the @var{n}th month of the year. |
16904 | 16892 |
16905 @kindex t W | 16893 @kindex t W |
16906 @pindex calc-new-week | 16894 @pindex calc-new-week |
16907 @tindex newweek | 16895 @tindex newweek |
16908 The @kbd{t W} (@code{calc-new-week}) [@code{newweek}] command | 16896 The @kbd{t W} (@code{calc-new-week}) [@code{newweek}] command |
17267 | 17255 |
17268 The Lisp variable @code{math-daylight-savings-hook} holds the | 17256 The Lisp variable @code{math-daylight-savings-hook} holds the |
17269 name of a function that is used to compute the daylight savings | 17257 name of a function that is used to compute the daylight savings |
17270 adjustment for a given date. The default is | 17258 adjustment for a given date. The default is |
17271 @code{math-std-daylight-savings}, which computes an adjustment | 17259 @code{math-std-daylight-savings}, which computes an adjustment |
17272 (either 0 or @i{-1}) using the North American rules given above. | 17260 (either 0 or @mathit{-1}) using the North American rules given above. |
17273 | 17261 |
17274 The daylight savings hook function is called with four arguments: | 17262 The daylight savings hook function is called with four arguments: |
17275 The date, as a floating-point number in standard Calc format; | 17263 The date, as a floating-point number in standard Calc format; |
17276 a six-element list of the date decomposed into year, month, day, | 17264 a six-element list of the date decomposed into year, month, day, |
17277 hour, minute, and second, respectively; a string which contains | 17265 hour, minute, and second, respectively; a string which contains |
17315 @end smallexample | 17303 @end smallexample |
17316 | 17304 |
17317 @noindent | 17305 @noindent |
17318 The @code{bump} parameter is equal to zero when Calc is converting | 17306 The @code{bump} parameter is equal to zero when Calc is converting |
17319 from a date form in a generalized time zone into a GMT date value. | 17307 from a date form in a generalized time zone into a GMT date value. |
17320 It is @i{-1} when Calc is converting in the other direction. The | 17308 It is @mathit{-1} when Calc is converting in the other direction. The |
17321 adjustments shown above ensure that the conversion behaves correctly | 17309 adjustments shown above ensure that the conversion behaves correctly |
17322 and reasonably around the 2 a.m.@: transition in each direction. | 17310 and reasonably around the 2 a.m.@: transition in each direction. |
17323 | 17311 |
17324 There is a ``missing'' hour between 2 a.m.@: and 3 a.m.@: at the | 17312 There is a ``missing'' hour between 2 a.m.@: and 3 a.m.@: at the |
17325 beginning of daylight savings time; converting a date/time form that | 17313 beginning of daylight savings time; converting a date/time form that |
17942 particular, negative arguments are converted to positive integers modulo | 17930 particular, negative arguments are converted to positive integers modulo |
17943 @expr{2^w} by all binary functions. | 17931 @expr{2^w} by all binary functions. |
17944 | 17932 |
17945 If the word size is negative, binary operations produce 2's complement | 17933 If the word size is negative, binary operations produce 2's complement |
17946 integers from | 17934 integers from |
17947 @texline @tmath{-2^{-w-1}} | 17935 @texline @math{-2^{-w-1}} |
17948 @infoline @expr{-(2^(-w-1))} | 17936 @infoline @expr{-(2^(-w-1))} |
17949 to | 17937 to |
17950 @texline @tmath{2^{-w-1}-1} | 17938 @texline @math{2^{-w-1}-1} |
17951 @infoline @expr{2^(-w-1)-1} | 17939 @infoline @expr{2^(-w-1)-1} |
17952 inclusive. Either mode accepts inputs in any range; the sign of | 17940 inclusive. Either mode accepts inputs in any range; the sign of |
17953 @expr{w} affects only the results produced. | 17941 @expr{w} affects only the results produced. |
17954 | 17942 |
17955 @kindex b c | 17943 @kindex b c |
17961 their results to the current word size. Note that other operations like | 17949 their results to the current word size. Note that other operations like |
17962 addition do not use the current word size, since integer addition | 17950 addition do not use the current word size, since integer addition |
17963 generally is not ``binary.'' (However, @pxref{Simplification Modes}, | 17951 generally is not ``binary.'' (However, @pxref{Simplification Modes}, |
17964 @code{calc-bin-simplify-mode}.) For example, with a word size of 8 | 17952 @code{calc-bin-simplify-mode}.) For example, with a word size of 8 |
17965 bits @kbd{b c} converts a number to the range 0 to 255; with a word | 17953 bits @kbd{b c} converts a number to the range 0 to 255; with a word |
17966 size of @i{-8} @kbd{b c} converts to the range @i{-128} to 127. | 17954 size of @mathit{-8} @kbd{b c} converts to the range @mathit{-128} to 127. |
17967 | 17955 |
17968 @kindex b w | 17956 @kindex b w |
17969 @pindex calc-word-size | 17957 @pindex calc-word-size |
17970 The default word size is 32 bits. All operations except the shifts and | 17958 The default word size is 32 bits. All operations except the shifts and |
17971 rotates allow you to specify a different word size for that one | 17959 rotates allow you to specify a different word size for that one |
17977 | 17965 |
17978 When the binary operations are written in symbolic form, they take an | 17966 When the binary operations are written in symbolic form, they take an |
17979 optional second (or third) word-size parameter. When a formula like | 17967 optional second (or third) word-size parameter. When a formula like |
17980 @samp{and(a,b)} is finally evaluated, the word size current at that time | 17968 @samp{and(a,b)} is finally evaluated, the word size current at that time |
17981 will be used, but when @samp{and(a,b,-8)} is evaluated, a word size of | 17969 will be used, but when @samp{and(a,b,-8)} is evaluated, a word size of |
17982 @i{-8} will always be used. A symbolic binary function will be left | 17970 @mathit{-8} will always be used. A symbolic binary function will be left |
17983 in symbolic form unless the all of its argument(s) are integers or | 17971 in symbolic form unless the all of its argument(s) are integers or |
17984 integer-valued floats. | 17972 integer-valued floats. |
17985 | 17973 |
17986 If either or both arguments are modulo forms for which @expr{M} is a | 17974 If either or both arguments are modulo forms for which @expr{M} is a |
17987 power of two, that power of two is taken as the word size unless a | 17975 power of two, that power of two is taken as the word size unless a |
18129 @cindex Golden ratio | 18117 @cindex Golden ratio |
18130 One miscellaneous command is shift-@kbd{P} (@code{calc-pi}), which pushes | 18118 One miscellaneous command is shift-@kbd{P} (@code{calc-pi}), which pushes |
18131 the value of @cpi{} (at the current precision) onto the stack. With the | 18119 the value of @cpi{} (at the current precision) onto the stack. With the |
18132 Hyperbolic flag, it pushes the value @expr{e}, the base of natural logarithms. | 18120 Hyperbolic flag, it pushes the value @expr{e}, the base of natural logarithms. |
18133 With the Inverse flag, it pushes Euler's constant | 18121 With the Inverse flag, it pushes Euler's constant |
18134 @texline @tmath{\gamma} | 18122 @texline @math{\gamma} |
18135 @infoline @expr{gamma} | 18123 @infoline @expr{gamma} |
18136 (about 0.5772). With both Inverse and Hyperbolic, it | 18124 (about 0.5772). With both Inverse and Hyperbolic, it |
18137 pushes the ``golden ratio'' | 18125 pushes the ``golden ratio'' |
18138 @texline @tmath{\phi} | 18126 @texline @math{\phi} |
18139 @infoline @expr{phi} | 18127 @infoline @expr{phi} |
18140 (about 1.618). (At present, Euler's constant is not available | 18128 (about 1.618). (At present, Euler's constant is not available |
18141 to unlimited precision; Calc knows only the first 100 digits.) | 18129 to unlimited precision; Calc knows only the first 100 digits.) |
18142 In Symbolic mode, these commands push the | 18130 In Symbolic mode, these commands push the |
18143 actual variables @samp{pi}, @samp{e}, @samp{gamma}, and @samp{phi}, | 18131 actual variables @samp{pi}, @samp{e}, @samp{gamma}, and @samp{phi}, |
18213 The @kbd{H L} (@code{calc-log10}) [@code{log10}] command computes the common | 18201 The @kbd{H L} (@code{calc-log10}) [@code{log10}] command computes the common |
18214 (base-10) logarithm of a number. (With the Inverse flag [@code{exp10}], | 18202 (base-10) logarithm of a number. (With the Inverse flag [@code{exp10}], |
18215 it raises ten to a given power.) Note that the common logarithm of a | 18203 it raises ten to a given power.) Note that the common logarithm of a |
18216 complex number is computed by taking the natural logarithm and dividing | 18204 complex number is computed by taking the natural logarithm and dividing |
18217 by | 18205 by |
18218 @texline @tmath{\ln10}. | 18206 @texline @math{\ln10}. |
18219 @infoline @expr{ln(10)}. | 18207 @infoline @expr{ln(10)}. |
18220 | 18208 |
18221 @kindex B | 18209 @kindex B |
18222 @kindex I B | 18210 @kindex I B |
18223 @pindex calc-log | 18211 @pindex calc-log |
18224 @tindex log | 18212 @tindex log |
18225 @tindex alog | 18213 @tindex alog |
18226 The @kbd{B} (@code{calc-log}) [@code{log}] command computes a logarithm | 18214 The @kbd{B} (@code{calc-log}) [@code{log}] command computes a logarithm |
18227 to any base. For example, @kbd{1024 @key{RET} 2 B} produces 10, since | 18215 to any base. For example, @kbd{1024 @key{RET} 2 B} produces 10, since |
18228 @texline @tmath{2^{10} = 1024}. | 18216 @texline @math{2^{10} = 1024}. |
18229 @infoline @expr{2^10 = 1024}. | 18217 @infoline @expr{2^10 = 1024}. |
18230 In certain cases like @samp{log(3,9)}, the result | 18218 In certain cases like @samp{log(3,9)}, the result |
18231 will be either @expr{1:2} or @expr{0.5} depending on the current Fraction | 18219 will be either @expr{1:2} or @expr{0.5} depending on the current Fraction |
18232 Mode setting. With the Inverse flag [@code{alog}], this command is | 18220 Mode setting. With the Inverse flag [@code{alog}], this command is |
18233 similar to @kbd{^} except that the order of the arguments is reversed. | 18221 similar to @kbd{^} except that the order of the arguments is reversed. |
18245 | 18233 |
18246 @kindex f E | 18234 @kindex f E |
18247 @pindex calc-expm1 | 18235 @pindex calc-expm1 |
18248 @tindex expm1 | 18236 @tindex expm1 |
18249 The @kbd{f E} (@code{calc-expm1}) [@code{expm1}] command computes | 18237 The @kbd{f E} (@code{calc-expm1}) [@code{expm1}] command computes |
18250 @texline @tmath{e^x - 1}, | 18238 @texline @math{e^x - 1}, |
18251 @infoline @expr{exp(x)-1}, | 18239 @infoline @expr{exp(x)-1}, |
18252 but using an algorithm that produces a more accurate | 18240 but using an algorithm that produces a more accurate |
18253 answer when the result is close to zero, i.e., when | 18241 answer when the result is close to zero, i.e., when |
18254 @texline @tmath{e^x} | 18242 @texline @math{e^x} |
18255 @infoline @expr{exp(x)} | 18243 @infoline @expr{exp(x)} |
18256 is close to one. | 18244 is close to one. |
18257 | 18245 |
18258 @kindex f L | 18246 @kindex f L |
18259 @pindex calc-lnp1 | 18247 @pindex calc-lnp1 |
18260 @tindex lnp1 | 18248 @tindex lnp1 |
18261 The @kbd{f L} (@code{calc-lnp1}) [@code{lnp1}] command computes | 18249 The @kbd{f L} (@code{calc-lnp1}) [@code{lnp1}] command computes |
18262 @texline @tmath{\ln(x+1)}, | 18250 @texline @math{\ln(x+1)}, |
18263 @infoline @expr{ln(x+1)}, | 18251 @infoline @expr{ln(x+1)}, |
18264 producing a more accurate answer when @expr{x} is close to zero. | 18252 producing a more accurate answer when @expr{x} is close to zero. |
18265 | 18253 |
18266 @node Trigonometric and Hyperbolic Functions, Advanced Math Functions, Logarithmic Functions, Scientific Functions | 18254 @node Trigonometric and Hyperbolic Functions, Advanced Math Functions, Logarithmic Functions, Scientific Functions |
18267 @section Trigonometric/Hyperbolic Functions | 18255 @section Trigonometric/Hyperbolic Functions |
18391 @kindex f T | 18379 @kindex f T |
18392 @pindex calc-arctan2 | 18380 @pindex calc-arctan2 |
18393 @tindex arctan2 | 18381 @tindex arctan2 |
18394 The @kbd{f T} (@code{calc-arctan2}) [@code{arctan2}] command takes two | 18382 The @kbd{f T} (@code{calc-arctan2}) [@code{arctan2}] command takes two |
18395 numbers from the stack and computes the arc tangent of their ratio. The | 18383 numbers from the stack and computes the arc tangent of their ratio. The |
18396 result is in the full range from @i{-180} (exclusive) to @i{+180} | 18384 result is in the full range from @mathit{-180} (exclusive) to @mathit{+180} |
18397 (inclusive) degrees, or the analogous range in radians. A similar | 18385 (inclusive) degrees, or the analogous range in radians. A similar |
18398 result would be obtained with @kbd{/} followed by @kbd{I T}, but the | 18386 result would be obtained with @kbd{/} followed by @kbd{I T}, but the |
18399 value would only be in the range from @i{-90} to @i{+90} degrees | 18387 value would only be in the range from @mathit{-90} to @mathit{+90} degrees |
18400 since the division loses information about the signs of the two | 18388 since the division loses information about the signs of the two |
18401 components, and an error might result from an explicit division by zero | 18389 components, and an error might result from an explicit division by zero |
18402 which @code{arctan2} would avoid. By (arbitrary) definition, | 18390 which @code{arctan2} would avoid. By (arbitrary) definition, |
18403 @samp{arctan2(0,0)=0}. | 18391 @samp{arctan2(0,0)=0}. |
18404 | 18392 |
18443 The @kbd{f g} (@code{calc-gamma}) [@code{gamma}] command computes the Euler | 18431 The @kbd{f g} (@code{calc-gamma}) [@code{gamma}] command computes the Euler |
18444 gamma function. For positive integer arguments, this is related to the | 18432 gamma function. For positive integer arguments, this is related to the |
18445 factorial function: @samp{gamma(n+1) = fact(n)}. For general complex | 18433 factorial function: @samp{gamma(n+1) = fact(n)}. For general complex |
18446 arguments the gamma function can be defined by the following definite | 18434 arguments the gamma function can be defined by the following definite |
18447 integral: | 18435 integral: |
18448 @texline @tmath{\Gamma(a) = \int_0^\infty t^{a-1} e^t dt}. | 18436 @texline @math{\Gamma(a) = \int_0^\infty t^{a-1} e^t dt}. |
18449 @infoline @expr{gamma(a) = integ(t^(a-1) exp(t), t, 0, inf)}. | 18437 @infoline @expr{gamma(a) = integ(t^(a-1) exp(t), t, 0, inf)}. |
18450 (The actual implementation uses far more efficient computational methods.) | 18438 (The actual implementation uses far more efficient computational methods.) |
18451 | 18439 |
18452 @kindex f G | 18440 @kindex f G |
18453 @tindex gammaP | 18441 @tindex gammaP |
18477 @end ignore | 18465 @end ignore |
18478 @tindex gammaG | 18466 @tindex gammaG |
18479 The @kbd{f G} (@code{calc-inc-gamma}) [@code{gammaP}] command computes | 18467 The @kbd{f G} (@code{calc-inc-gamma}) [@code{gammaP}] command computes |
18480 the incomplete gamma function, denoted @samp{P(a,x)}. This is defined by | 18468 the incomplete gamma function, denoted @samp{P(a,x)}. This is defined by |
18481 the integral, | 18469 the integral, |
18482 @texline @tmath{P(a,x) = \left( \int_0^x t^{a-1} e^t dt \right) / \Gamma(a)}. | 18470 @texline @math{P(a,x) = \left( \int_0^x t^{a-1} e^t dt \right) / \Gamma(a)}. |
18483 @infoline @expr{gammaP(a,x) = integ(t^(a-1) exp(t), t, 0, x) / gamma(a)}. | 18471 @infoline @expr{gammaP(a,x) = integ(t^(a-1) exp(t), t, 0, x) / gamma(a)}. |
18484 This implies that @samp{gammaP(a,inf) = 1} for any @expr{a} (see the | 18472 This implies that @samp{gammaP(a,inf) = 1} for any @expr{a} (see the |
18485 definition of the normal gamma function). | 18473 definition of the normal gamma function). |
18486 | 18474 |
18487 Several other varieties of incomplete gamma function are defined. | 18475 Several other varieties of incomplete gamma function are defined. |
18510 @kindex f b | 18498 @kindex f b |
18511 @pindex calc-beta | 18499 @pindex calc-beta |
18512 @tindex beta | 18500 @tindex beta |
18513 The @kbd{f b} (@code{calc-beta}) [@code{beta}] command computes the | 18501 The @kbd{f b} (@code{calc-beta}) [@code{beta}] command computes the |
18514 Euler beta function, which is defined in terms of the gamma function as | 18502 Euler beta function, which is defined in terms of the gamma function as |
18515 @texline @tmath{B(a,b) = \Gamma(a) \Gamma(b) / \Gamma(a+b)}, | 18503 @texline @math{B(a,b) = \Gamma(a) \Gamma(b) / \Gamma(a+b)}, |
18516 @infoline @expr{beta(a,b) = gamma(a) gamma(b) / gamma(a+b)}, | 18504 @infoline @expr{beta(a,b) = gamma(a) gamma(b) / gamma(a+b)}, |
18517 or by | 18505 or by |
18518 @texline @tmath{B(a,b) = \int_0^1 t^{a-1} (1-t)^{b-1} dt}. | 18506 @texline @math{B(a,b) = \int_0^1 t^{a-1} (1-t)^{b-1} dt}. |
18519 @infoline @expr{beta(a,b) = integ(t^(a-1) (1-t)^(b-1), t, 0, 1)}. | 18507 @infoline @expr{beta(a,b) = integ(t^(a-1) (1-t)^(b-1), t, 0, 1)}. |
18520 | 18508 |
18521 @kindex f B | 18509 @kindex f B |
18522 @kindex H f B | 18510 @kindex H f B |
18523 @pindex calc-inc-beta | 18511 @pindex calc-inc-beta |
18524 @tindex betaI | 18512 @tindex betaI |
18525 @tindex betaB | 18513 @tindex betaB |
18526 The @kbd{f B} (@code{calc-inc-beta}) [@code{betaI}] command computes | 18514 The @kbd{f B} (@code{calc-inc-beta}) [@code{betaI}] command computes |
18527 the incomplete beta function @expr{I(x,a,b)}. It is defined by | 18515 the incomplete beta function @expr{I(x,a,b)}. It is defined by |
18528 @texline @tmath{I(x,a,b) = \left( \int_0^x t^{a-1} (1-t)^{b-1} dt \right) / B(a,b)}. | 18516 @texline @math{I(x,a,b) = \left( \int_0^x t^{a-1} (1-t)^{b-1} dt \right) / B(a,b)}. |
18529 @infoline @expr{betaI(x,a,b) = integ(t^(a-1) (1-t)^(b-1), t, 0, x) / beta(a,b)}. | 18517 @infoline @expr{betaI(x,a,b) = integ(t^(a-1) (1-t)^(b-1), t, 0, x) / beta(a,b)}. |
18530 Once again, the @kbd{H} (hyperbolic) prefix gives the corresponding | 18518 Once again, the @kbd{H} (hyperbolic) prefix gives the corresponding |
18531 un-normalized version [@code{betaB}]. | 18519 un-normalized version [@code{betaB}]. |
18532 | 18520 |
18533 @kindex f e | 18521 @kindex f e |
18535 @pindex calc-erf | 18523 @pindex calc-erf |
18536 @tindex erf | 18524 @tindex erf |
18537 @tindex erfc | 18525 @tindex erfc |
18538 The @kbd{f e} (@code{calc-erf}) [@code{erf}] command computes the | 18526 The @kbd{f e} (@code{calc-erf}) [@code{erf}] command computes the |
18539 error function | 18527 error function |
18540 @texline @tmath{\hbox{erf}(x) = {2 \over \sqrt{\pi}} \int_0^x e^{-t^2} dt}. | 18528 @texline @math{\hbox{erf}(x) = {2 \over \sqrt{\pi}} \int_0^x e^{-t^2} dt}. |
18541 @infoline @expr{erf(x) = 2 integ(exp(-(t^2)), t, 0, x) / sqrt(pi)}. | 18529 @infoline @expr{erf(x) = 2 integ(exp(-(t^2)), t, 0, x) / sqrt(pi)}. |
18542 The complementary error function @kbd{I f e} (@code{calc-erfc}) [@code{erfc}] | 18530 The complementary error function @kbd{I f e} (@code{calc-erfc}) [@code{erfc}] |
18543 is the corresponding integral from @samp{x} to infinity; the sum | 18531 is the corresponding integral from @samp{x} to infinity; the sum |
18544 @texline @tmath{\hbox{erf}(x) + \hbox{erfc}(x) = 1}. | 18532 @texline @math{\hbox{erf}(x) + \hbox{erfc}(x) = 1}. |
18545 @infoline @expr{erf(x) + erfc(x) = 1}. | 18533 @infoline @expr{erf(x) + erfc(x) = 1}. |
18546 | 18534 |
18547 @kindex f j | 18535 @kindex f j |
18548 @kindex f y | 18536 @kindex f y |
18549 @pindex calc-bessel-J | 18537 @pindex calc-bessel-J |
18615 -, -eps +eps, - +eps, - | 18603 -, -eps +eps, - +eps, - |
18616 @end smallexample | 18604 @end smallexample |
18617 | 18605 |
18618 For @samp{z1^z2}: This is defined by @samp{exp(ln(z1)*z2)}. | 18606 For @samp{z1^z2}: This is defined by @samp{exp(ln(z1)*z2)}. |
18619 One interesting consequence of this is that @samp{(-8)^1:3} does | 18607 One interesting consequence of this is that @samp{(-8)^1:3} does |
18620 not evaluate to @i{-2} as you might expect, but to the complex | 18608 not evaluate to @mathit{-2} as you might expect, but to the complex |
18621 number @expr{(1., 1.732)}. Both of these are valid cube roots | 18609 number @expr{(1., 1.732)}. Both of these are valid cube roots |
18622 of @i{-8} (as is @expr{(1., -1.732)}); Calc chooses a perhaps | 18610 of @mathit{-8} (as is @expr{(1., -1.732)}); Calc chooses a perhaps |
18623 less-obvious root for the sake of mathematical consistency. | 18611 less-obvious root for the sake of mathematical consistency. |
18624 | 18612 |
18625 For @samp{arcsin(z)}: This is defined by @samp{-i*ln(i*z + sqrt(1-z^2))}. | 18613 For @samp{arcsin(z)}: This is defined by @samp{-i*ln(i*z + sqrt(1-z^2))}. |
18626 The branch cuts are on the real axis, less than @i{-1} and greater than 1. | 18614 The branch cuts are on the real axis, less than @mathit{-1} and greater than 1. |
18627 | 18615 |
18628 For @samp{arccos(z)}: This is defined by @samp{-i*ln(z + i*sqrt(1-z^2))}, | 18616 For @samp{arccos(z)}: This is defined by @samp{-i*ln(z + i*sqrt(1-z^2))}, |
18629 or equivalently by @samp{pi/2 - arcsin(z)}. The branch cuts are on | 18617 or equivalently by @samp{pi/2 - arcsin(z)}. The branch cuts are on |
18630 the real axis, less than @i{-1} and greater than 1. | 18618 the real axis, less than @mathit{-1} and greater than 1. |
18631 | 18619 |
18632 For @samp{arctan(z)}: This is defined by | 18620 For @samp{arctan(z)}: This is defined by |
18633 @samp{(ln(1+i*z) - ln(1-i*z)) / (2*i)}. The branch cuts are on the | 18621 @samp{(ln(1+i*z) - ln(1-i*z)) / (2*i)}. The branch cuts are on the |
18634 imaginary axis, below @expr{-i} and above @expr{i}. | 18622 imaginary axis, below @expr{-i} and above @expr{i}. |
18635 | 18623 |
18640 For @samp{arccosh(z)}: This is defined by | 18628 For @samp{arccosh(z)}: This is defined by |
18641 @samp{ln(z + (z+1)*sqrt((z-1)/(z+1)))}. The branch cut is on the | 18629 @samp{ln(z + (z+1)*sqrt((z-1)/(z+1)))}. The branch cut is on the |
18642 real axis less than 1. | 18630 real axis less than 1. |
18643 | 18631 |
18644 For @samp{arctanh(z)}: This is defined by @samp{(ln(1+z) - ln(1-z)) / 2}. | 18632 For @samp{arctanh(z)}: This is defined by @samp{(ln(1+z) - ln(1-z)) / 2}. |
18645 The branch cuts are on the real axis, less than @i{-1} and greater than 1. | 18633 The branch cuts are on the real axis, less than @mathit{-1} and greater than 1. |
18646 | 18634 |
18647 The following tables for @code{arcsin}, @code{arccos}, and | 18635 The following tables for @code{arcsin}, @code{arccos}, and |
18648 @code{arctan} assume the current angular mode is radians. The | 18636 @code{arctan} assume the current angular mode is radians. The |
18649 hyperbolic functions operate independently of the angular mode. | 18637 hyperbolic functions operate independently of the angular mode. |
18650 | 18638 |
18713 The @kbd{k r} (@code{calc-random}) [@code{random}] command produces | 18701 The @kbd{k r} (@code{calc-random}) [@code{random}] command produces |
18714 random numbers of various sorts. | 18702 random numbers of various sorts. |
18715 | 18703 |
18716 Given a positive numeric prefix argument @expr{M}, it produces a random | 18704 Given a positive numeric prefix argument @expr{M}, it produces a random |
18717 integer @expr{N} in the range | 18705 integer @expr{N} in the range |
18718 @texline @tmath{0 \le N < M}. | 18706 @texline @math{0 \le N < M}. |
18719 @infoline @expr{0 <= N < M}. | 18707 @infoline @expr{0 <= N < M}. |
18720 Each of the @expr{M} values appears with equal probability. | 18708 Each of the @expr{M} values appears with equal probability. |
18721 | 18709 |
18722 With no numeric prefix argument, the @kbd{k r} command takes its argument | 18710 With no numeric prefix argument, the @kbd{k r} command takes its argument |
18723 from the stack instead. Once again, if this is a positive integer @expr{M} | 18711 from the stack instead. Once again, if this is a positive integer @expr{M} |
18724 the result is a random integer less than @expr{M}. However, note that | 18712 the result is a random integer less than @expr{M}. However, note that |
18725 while numeric prefix arguments are limited to six digits or so, an @expr{M} | 18713 while numeric prefix arguments are limited to six digits or so, an @expr{M} |
18726 taken from the stack can be arbitrarily large. If @expr{M} is negative, | 18714 taken from the stack can be arbitrarily large. If @expr{M} is negative, |
18727 the result is a random integer in the range | 18715 the result is a random integer in the range |
18728 @texline @tmath{M < N \le 0}. | 18716 @texline @math{M < N \le 0}. |
18729 @infoline @expr{M < N <= 0}. | 18717 @infoline @expr{M < N <= 0}. |
18730 | 18718 |
18731 If the value on the stack is a floating-point number @expr{M}, the result | 18719 If the value on the stack is a floating-point number @expr{M}, the result |
18732 is a random floating-point number @expr{N} in the range | 18720 is a random floating-point number @expr{N} in the range |
18733 @texline @tmath{0 \le N < M} | 18721 @texline @math{0 \le N < M} |
18734 @infoline @expr{0 <= N < M} | 18722 @infoline @expr{0 <= N < M} |
18735 or | 18723 or |
18736 @texline @tmath{M < N \le 0}, | 18724 @texline @math{M < N \le 0}, |
18737 @infoline @expr{M < N <= 0}, | 18725 @infoline @expr{M < N <= 0}, |
18738 according to the sign of @expr{M}. | 18726 according to the sign of @expr{M}. |
18739 | 18727 |
18740 If @expr{M} is zero, the result is a Gaussian-distributed random real | 18728 If @expr{M} is zero, the result is a Gaussian-distributed random real |
18741 number; the distribution has a mean of zero and a standard deviation | 18729 number; the distribution has a mean of zero and a standard deviation |
18742 of one. The algorithm used generates random numbers in pairs; thus, | 18730 of one. The algorithm used generates random numbers in pairs; thus, |
18743 every other call to this function will be especially fast. | 18731 every other call to this function will be especially fast. |
18744 | 18732 |
18745 If @expr{M} is an error form | 18733 If @expr{M} is an error form |
18746 @texline @tmath{m} @code{+/-} @tmath{\sigma} | 18734 @texline @math{m} @code{+/-} @math{\sigma} |
18747 @infoline @samp{m +/- s} | 18735 @infoline @samp{m +/- s} |
18748 where @var{m} and | 18736 where @var{m} and |
18749 @texline @tmath{\sigma} | 18737 @texline @math{\sigma} |
18750 @infoline @var{s} | 18738 @infoline @var{s} |
18751 are both real numbers, the result uses a Gaussian distribution with mean | 18739 are both real numbers, the result uses a Gaussian distribution with mean |
18752 @var{m} and standard deviation | 18740 @var{m} and standard deviation |
18753 @texline @tmath{\sigma}. | 18741 @texline @math{\sigma}. |
18754 @var{s}. | 18742 @var{s}. |
18755 | 18743 |
18756 If @expr{M} is an interval form, the lower and upper bounds specify the | 18744 If @expr{M} is an interval form, the lower and upper bounds specify the |
18757 acceptable limits of the random numbers. If both bounds are integers, | 18745 acceptable limits of the random numbers. If both bounds are integers, |
18758 the result is a random integer in the specified range. If either bound | 18746 the result is a random integer in the specified range. If either bound |
18861 generators that are typically used to implement @code{random}. | 18849 generators that are typically used to implement @code{random}. |
18862 | 18850 |
18863 If @code{RandSeed} contains an integer, Calc uses this integer to | 18851 If @code{RandSeed} contains an integer, Calc uses this integer to |
18864 seed an ``additive congruential'' method (Knuth's algorithm 3.2.2A, | 18852 seed an ``additive congruential'' method (Knuth's algorithm 3.2.2A, |
18865 computing | 18853 computing |
18866 @texline @tmath{X_{n-55} - X_{n-24}}. | 18854 @texline @math{X_{n-55} - X_{n-24}}. |
18867 @infoline @expr{X_n-55 - X_n-24}). | 18855 @infoline @expr{X_n-55 - X_n-24}). |
18868 This method expands the seed | 18856 This method expands the seed |
18869 value into a large table which is maintained internally; the variable | 18857 value into a large table which is maintained internally; the variable |
18870 @code{RandSeed} is changed from, e.g., 42 to the vector @expr{[42]} | 18858 @code{RandSeed} is changed from, e.g., 42 to the vector @expr{[42]} |
18871 to indicate that the seed has been absorbed into this table. When | 18859 to indicate that the seed has been absorbed into this table. When |
18897 or more, Calc throws it out and tries again until it gets a suitable | 18885 or more, Calc throws it out and tries again until it gets a suitable |
18898 value. | 18886 value. |
18899 | 18887 |
18900 To create a random floating-point number with precision @var{p}, Calc | 18888 To create a random floating-point number with precision @var{p}, Calc |
18901 simply creates a random @var{p}-digit integer and multiplies by | 18889 simply creates a random @var{p}-digit integer and multiplies by |
18902 @texline @tmath{10^{-p}}. | 18890 @texline @math{10^{-p}}. |
18903 @infoline @expr{10^-p}. | 18891 @infoline @expr{10^-p}. |
18904 The resulting random numbers should be very clean, but note | 18892 The resulting random numbers should be very clean, but note |
18905 that relatively small numbers will have few significant random digits. | 18893 that relatively small numbers will have few significant random digits. |
18906 In other words, with a precision of 12, you will occasionally get | 18894 In other words, with a precision of 12, you will occasionally get |
18907 numbers on the order of | 18895 numbers on the order of |
18908 @texline @tmath{10^{-9}} | 18896 @texline @math{10^{-9}} |
18909 @infoline @expr{10^-9} | 18897 @infoline @expr{10^-9} |
18910 or | 18898 or |
18911 @texline @tmath{10^{-10}}, | 18899 @texline @math{10^{-10}}, |
18912 @infoline @expr{10^-10}, | 18900 @infoline @expr{10^-10}, |
18913 but those numbers will only have two or three random digits since they | 18901 but those numbers will only have two or three random digits since they |
18914 correspond to small integers times | 18902 correspond to small integers times |
18915 @texline @tmath{10^{-12}}. | 18903 @texline @math{10^{-12}}. |
18916 @infoline @expr{10^-12}. | 18904 @infoline @expr{10^-12}. |
18917 | 18905 |
18918 To create a random integer in the interval @samp{[0 .. @var{m})}, Calc | 18906 To create a random integer in the interval @samp{[0 .. @var{m})}, Calc |
18919 counts the digits in @var{m}, creates a random integer with three | 18907 counts the digits in @var{m}, creates a random integer with three |
18920 additional digits, then reduces modulo @var{m}. Unless @var{m} is a | 18908 additional digits, then reduces modulo @var{m}. Unless @var{m} is a |
18961 @pindex calc-extended-gcd | 18949 @pindex calc-extended-gcd |
18962 @tindex egcd | 18950 @tindex egcd |
18963 The @kbd{k E} (@code{calc-extended-gcd}) [@code{egcd}] command computes | 18951 The @kbd{k E} (@code{calc-extended-gcd}) [@code{egcd}] command computes |
18964 the GCD of two integers @expr{x} and @expr{y} and returns a vector | 18952 the GCD of two integers @expr{x} and @expr{y} and returns a vector |
18965 @expr{[g, a, b]} where | 18953 @expr{[g, a, b]} where |
18966 @texline @tmath{g = \gcd(x,y) = a x + b y}. | 18954 @texline @math{g = \gcd(x,y) = a x + b y}. |
18967 @infoline @expr{g = gcd(x,y) = a x + b y}. | 18955 @infoline @expr{g = gcd(x,y) = a x + b y}. |
18968 | 18956 |
18969 @kindex ! | 18957 @kindex ! |
18970 @pindex calc-factorial | 18958 @pindex calc-factorial |
18971 @tindex fact | 18959 @tindex fact |
19005 binomial coefficient @expr{N}-choose-@expr{M}, where @expr{M} is the number | 18993 binomial coefficient @expr{N}-choose-@expr{M}, where @expr{M} is the number |
19006 on the top of the stack and @expr{N} is second-to-top. If both arguments | 18994 on the top of the stack and @expr{N} is second-to-top. If both arguments |
19007 are integers, the result is an exact integer. Otherwise, the result is a | 18995 are integers, the result is an exact integer. Otherwise, the result is a |
19008 floating-point approximation. The binomial coefficient is defined for all | 18996 floating-point approximation. The binomial coefficient is defined for all |
19009 real numbers by | 18997 real numbers by |
19010 @texline @tmath{N! \over M! (N-M)!\,}. | 18998 @texline @math{N! \over M! (N-M)!\,}. |
19011 @infoline @expr{N! / M! (N-M)!}. | 18999 @infoline @expr{N! / M! (N-M)!}. |
19012 | 19000 |
19013 @kindex H k c | 19001 @kindex H k c |
19014 @pindex calc-perm | 19002 @pindex calc-perm |
19015 @tindex perm | 19003 @tindex perm |
19048 @pindex calc-stirling-number | 19036 @pindex calc-stirling-number |
19049 @tindex stir1 | 19037 @tindex stir1 |
19050 @tindex stir2 | 19038 @tindex stir2 |
19051 The @kbd{k s} (@code{calc-stirling-number}) [@code{stir1}] command | 19039 The @kbd{k s} (@code{calc-stirling-number}) [@code{stir1}] command |
19052 computes a Stirling number of the first | 19040 computes a Stirling number of the first |
19053 @texline kind@tie{}@tmath{n \brack m}, | 19041 @texline kind@tie{}@math{n \brack m}, |
19054 @infoline kind, | 19042 @infoline kind, |
19055 given two integers @expr{n} and @expr{m} on the stack. The @kbd{H k s} | 19043 given two integers @expr{n} and @expr{m} on the stack. The @kbd{H k s} |
19056 [@code{stir2}] command computes a Stirling number of the second | 19044 [@code{stir2}] command computes a Stirling number of the second |
19057 @texline kind@tie{}@tmath{n \brace m}. | 19045 @texline kind@tie{}@math{n \brace m}. |
19058 @infoline kind. | 19046 @infoline kind. |
19059 These are the number of @expr{m}-cycle permutations of @expr{n} objects, | 19047 These are the number of @expr{m}-cycle permutations of @expr{n} objects, |
19060 and the number of ways to partition @expr{n} objects into @expr{m} | 19048 and the number of ways to partition @expr{n} objects into @expr{m} |
19061 non-empty sets, respectively. | 19049 non-empty sets, respectively. |
19062 | 19050 |
19096 to 25 million, the answer is exact although it may take some time. The | 19084 to 25 million, the answer is exact although it may take some time. The |
19097 result is a vector of the prime factors in increasing order. For larger | 19085 result is a vector of the prime factors in increasing order. For larger |
19098 inputs, prime factors above 5000 may not be found, in which case the | 19086 inputs, prime factors above 5000 may not be found, in which case the |
19099 last number in the vector will be an unfactored integer greater than 25 | 19087 last number in the vector will be an unfactored integer greater than 25 |
19100 million (with a warning message). For negative integers, the first | 19088 million (with a warning message). For negative integers, the first |
19101 element of the list will be @i{-1}. For inputs @i{-1}, @i{0}, and | 19089 element of the list will be @mathit{-1}. For inputs @mathit{-1}, @mathit{0}, and |
19102 @i{1}, the result is a list of the same number. | 19090 @mathit{1}, the result is a list of the same number. |
19103 | 19091 |
19104 @kindex k n | 19092 @kindex k n |
19105 @pindex calc-next-prime | 19093 @pindex calc-next-prime |
19106 @ignore | 19094 @ignore |
19107 @mindex nextpr@idots | 19095 @mindex nextpr@idots |
19131 @kindex k t | 19119 @kindex k t |
19132 @pindex calc-totient | 19120 @pindex calc-totient |
19133 @tindex totient | 19121 @tindex totient |
19134 The @kbd{k t} (@code{calc-totient}) [@code{totient}] command computes the | 19122 The @kbd{k t} (@code{calc-totient}) [@code{totient}] command computes the |
19135 Euler ``totient'' | 19123 Euler ``totient'' |
19136 @texline function@tie{}@tmath{\phi(n)}, | 19124 @texline function@tie{}@math{\phi(n)}, |
19137 @infoline function, | 19125 @infoline function, |
19138 the number of integers less than @expr{n} which | 19126 the number of integers less than @expr{n} which |
19139 are relatively prime to @expr{n}. | 19127 are relatively prime to @expr{n}. |
19140 | 19128 |
19141 @kindex k m | 19129 @kindex k m |
19142 @pindex calc-moebius | 19130 @pindex calc-moebius |
19143 @tindex moebius | 19131 @tindex moebius |
19144 The @kbd{k m} (@code{calc-moebius}) [@code{moebius}] command computes the | 19132 The @kbd{k m} (@code{calc-moebius}) [@code{moebius}] command computes the |
19145 @texline M@"obius @tmath{\mu} | 19133 @texline M@"obius @math{\mu} |
19146 @infoline Moebius ``mu'' | 19134 @infoline Moebius ``mu'' |
19147 function. If the input number is a product of @expr{k} | 19135 function. If the input number is a product of @expr{k} |
19148 distinct factors, this is @expr{(-1)^k}. If the input number has any | 19136 distinct factors, this is @expr{(-1)^k}. If the input number has any |
19149 duplicate factors (i.e., can be divided by the same prime more than once), | 19137 duplicate factors (i.e., can be divided by the same prime more than once), |
19150 the result is zero. | 19138 the result is zero. |
19204 @ignore | 19192 @ignore |
19205 @mindex @null | 19193 @mindex @null |
19206 @end ignore | 19194 @end ignore |
19207 @tindex ltpc | 19195 @tindex ltpc |
19208 The @samp{utpc(x,v)} function uses the chi-square distribution with | 19196 The @samp{utpc(x,v)} function uses the chi-square distribution with |
19209 @texline @tmath{\nu} | 19197 @texline @math{\nu} |
19210 @infoline @expr{v} | 19198 @infoline @expr{v} |
19211 degrees of freedom. It is the probability that a model is | 19199 degrees of freedom. It is the probability that a model is |
19212 correct if its chi-square statistic is @expr{x}. | 19200 correct if its chi-square statistic is @expr{x}. |
19213 | 19201 |
19214 @kindex k F | 19202 @kindex k F |
19222 @mindex @null | 19210 @mindex @null |
19223 @end ignore | 19211 @end ignore |
19224 @tindex ltpf | 19212 @tindex ltpf |
19225 The @samp{utpf(F,v1,v2)} function uses the F distribution, used in | 19213 The @samp{utpf(F,v1,v2)} function uses the F distribution, used in |
19226 various statistical tests. The parameters | 19214 various statistical tests. The parameters |
19227 @texline @tmath{\nu_1} | 19215 @texline @math{\nu_1} |
19228 @infoline @expr{v1} | 19216 @infoline @expr{v1} |
19229 and | 19217 and |
19230 @texline @tmath{\nu_2} | 19218 @texline @math{\nu_2} |
19231 @infoline @expr{v2} | 19219 @infoline @expr{v2} |
19232 are the degrees of freedom in the numerator and denominator, | 19220 are the degrees of freedom in the numerator and denominator, |
19233 respectively, used in computing the statistic @expr{F}. | 19221 respectively, used in computing the statistic @expr{F}. |
19234 | 19222 |
19235 @kindex k N | 19223 @kindex k N |
19243 @mindex @null | 19231 @mindex @null |
19244 @end ignore | 19232 @end ignore |
19245 @tindex ltpn | 19233 @tindex ltpn |
19246 The @samp{utpn(x,m,s)} function uses a normal (Gaussian) distribution | 19234 The @samp{utpn(x,m,s)} function uses a normal (Gaussian) distribution |
19247 with mean @expr{m} and standard deviation | 19235 with mean @expr{m} and standard deviation |
19248 @texline @tmath{\sigma}. | 19236 @texline @math{\sigma}. |
19249 @infoline @expr{s}. | 19237 @infoline @expr{s}. |
19250 It is the probability that such a normal-distributed random variable | 19238 It is the probability that such a normal-distributed random variable |
19251 would exceed @expr{x}. | 19239 would exceed @expr{x}. |
19252 | 19240 |
19253 @kindex k P | 19241 @kindex k P |
19276 @mindex @null | 19264 @mindex @null |
19277 @end ignore | 19265 @end ignore |
19278 @tindex ltpt | 19266 @tindex ltpt |
19279 The @samp{utpt(t,v)} function uses the Student's ``t'' distribution | 19267 The @samp{utpt(t,v)} function uses the Student's ``t'' distribution |
19280 with | 19268 with |
19281 @texline @tmath{\nu} | 19269 @texline @math{\nu} |
19282 @infoline @expr{v} | 19270 @infoline @expr{v} |
19283 degrees of freedom. It is the probability that a | 19271 degrees of freedom. It is the probability that a |
19284 t-distributed random variable will be greater than @expr{t}. | 19272 t-distributed random variable will be greater than @expr{t}. |
19285 (Note: This computes the distribution function | 19273 (Note: This computes the distribution function |
19286 @texline @tmath{A(t|\nu)} | 19274 @texline @math{A(t|\nu)} |
19287 @infoline @expr{A(t|v)} | 19275 @infoline @expr{A(t|v)} |
19288 where | 19276 where |
19289 @texline @tmath{A(0|\nu) = 1} | 19277 @texline @math{A(0|\nu) = 1} |
19290 @infoline @expr{A(0|v) = 1} | 19278 @infoline @expr{A(0|v) = 1} |
19291 and | 19279 and |
19292 @texline @tmath{A(\infty|\nu) \to 0}. | 19280 @texline @math{A(\infty|\nu) \to 0}. |
19293 @infoline @expr{A(inf|v) -> 0}. | 19281 @infoline @expr{A(inf|v) -> 0}. |
19294 The @code{UTPT} operation on the HP-48 uses a different definition which | 19282 The @code{UTPT} operation on the HP-48 uses a different definition which |
19295 returns half of Calc's value: @samp{UTPT(t,v) = .5*utpt(t,v)}.) | 19283 returns half of Calc's value: @samp{UTPT(t,v) = .5*utpt(t,v)}.) |
19296 | 19284 |
19297 While Calc does not provide inverses of the probability distribution | 19285 While Calc does not provide inverses of the probability distribution |
19407 The first is the mantissa; the second, which must be an | 19395 The first is the mantissa; the second, which must be an |
19408 integer, is the exponent. The result is the mantissa | 19396 integer, is the exponent. The result is the mantissa |
19409 times ten to the power of the exponent. | 19397 times ten to the power of the exponent. |
19410 | 19398 |
19411 @item -12 | 19399 @item -12 |
19412 This is treated the same as @i{-11} by the @kbd{v p} command. | 19400 This is treated the same as @mathit{-11} by the @kbd{v p} command. |
19413 When unpacking, @i{-12} specifies that a floating-point mantissa | 19401 When unpacking, @mathit{-12} specifies that a floating-point mantissa |
19414 is desired. | 19402 is desired. |
19415 | 19403 |
19416 @item -13 | 19404 @item -13 |
19417 A real number is converted into a date form. | 19405 A real number is converted into a date form. |
19418 | 19406 |
19447 returned in the form @samp{[@w{[a, b, c]}, [d, e, f]]}. | 19435 returned in the form @samp{[@w{[a, b, c]}, [d, e, f]]}. |
19448 | 19436 |
19449 If any elements of the vector are negative, other kinds of | 19437 If any elements of the vector are negative, other kinds of |
19450 packing are done at that level as described above. For | 19438 packing are done at that level as described above. For |
19451 example, @samp{[2, 3, -4]} takes 12 objects and creates a | 19439 example, @samp{[2, 3, -4]} takes 12 objects and creates a |
19452 @texline @tmath{2\times3} | 19440 @texline @math{2\times3} |
19453 @infoline 2x3 | 19441 @infoline 2x3 |
19454 matrix of error forms: @samp{[[a +/- b, c +/- d ... ]]}. | 19442 matrix of error forms: @samp{[[a +/- b, c +/- d ... ]]}. |
19455 Also, @samp{[-4, -10]} will convert four integers into an | 19443 Also, @samp{[-4, -10]} will convert four integers into an |
19456 error form consisting of two fractions: @samp{a:b +/- c:d}. | 19444 error form consisting of two fractions: @samp{a:b +/- c:d}. |
19457 | 19445 |
19485 For example, given the vector @samp{[@w{a +/- b}, c^2, d +/- 7]}, | 19473 For example, given the vector @samp{[@w{a +/- b}, c^2, d +/- 7]}, |
19486 the result of @kbd{C-u -4 v u} will be the two vectors | 19474 the result of @kbd{C-u -4 v u} will be the two vectors |
19487 @samp{[a, c^2, d]} and @w{@samp{[b, 0, 7]}}. | 19475 @samp{[a, c^2, d]} and @w{@samp{[b, 0, 7]}}. |
19488 | 19476 |
19489 Note that the prefix argument can have an effect even when the input is | 19477 Note that the prefix argument can have an effect even when the input is |
19490 not a vector. For example, if the input is the number @i{-5}, then | 19478 not a vector. For example, if the input is the number @mathit{-5}, then |
19491 @kbd{c-u -1 v u} yields @i{-5} and 0 (the components of @i{-5} | 19479 @kbd{c-u -1 v u} yields @mathit{-5} and 0 (the components of @mathit{-5} |
19492 when viewed as a rectangular complex number); @kbd{C-u -2 v u} yields 5 | 19480 when viewed as a rectangular complex number); @kbd{C-u -2 v u} yields 5 |
19493 and 180 (assuming degrees mode); and @kbd{C-u -10 v u} yields @i{-5} | 19481 and 180 (assuming degrees mode); and @kbd{C-u -10 v u} yields @mathit{-5} |
19494 and 1 (the numerator and denominator of @i{-5}, viewed as a rational | 19482 and 1 (the numerator and denominator of @mathit{-5}, viewed as a rational |
19495 number). Plain @kbd{v u} with this input would complain that the input | 19483 number). Plain @kbd{v u} with this input would complain that the input |
19496 is not a composite object. | 19484 is not a composite object. |
19497 | 19485 |
19498 Unpacking mode @i{-11} converts a float into an integer mantissa and | 19486 Unpacking mode @mathit{-11} converts a float into an integer mantissa and |
19499 an integer exponent, where the mantissa is not divisible by 10 | 19487 an integer exponent, where the mantissa is not divisible by 10 |
19500 (except that 0.0 is represented by a mantissa and exponent of 0). | 19488 (except that 0.0 is represented by a mantissa and exponent of 0). |
19501 Unpacking mode @i{-12} converts a float into a floating-point mantissa | 19489 Unpacking mode @mathit{-12} converts a float into a floating-point mantissa |
19502 and integer exponent, where the mantissa (for non-zero numbers) | 19490 and integer exponent, where the mantissa (for non-zero numbers) |
19503 is guaranteed to lie in the range [1 .. 10). In both cases, | 19491 is guaranteed to lie in the range [1 .. 10). In both cases, |
19504 the mantissa is shifted left or right (and the exponent adjusted | 19492 the mantissa is shifted left or right (and the exponent adjusted |
19505 to compensate) in order to satisfy these constraints. | 19493 to compensate) in order to satisfy these constraints. |
19506 | 19494 |
19596 prefix, if specified, must match the size of the vector. If the value on | 19584 prefix, if specified, must match the size of the vector. If the value on |
19597 the stack is a scalar, it is used for each element on the diagonal, and | 19585 the stack is a scalar, it is used for each element on the diagonal, and |
19598 the prefix argument is required. | 19586 the prefix argument is required. |
19599 | 19587 |
19600 To build a constant square matrix, e.g., a | 19588 To build a constant square matrix, e.g., a |
19601 @texline @tmath{3\times3} | 19589 @texline @math{3\times3} |
19602 @infoline 3x3 | 19590 @infoline 3x3 |
19603 matrix filled with ones, use @kbd{0 M-3 v d 1 +}, i.e., build a zero | 19591 matrix filled with ones, use @kbd{0 M-3 v d 1 +}, i.e., build a zero |
19604 matrix first and then add a constant value to that matrix. (Another | 19592 matrix first and then add a constant value to that matrix. (Another |
19605 alternative would be to use @kbd{v b} and @kbd{v a}; see below.) | 19593 alternative would be to use @kbd{v b} and @kbd{v a}; see below.) |
19606 | 19594 |
19629 @tindex index | 19617 @tindex index |
19630 The @kbd{v x} (@code{calc-index}) [@code{index}] function builds a vector | 19618 The @kbd{v x} (@code{calc-index}) [@code{index}] function builds a vector |
19631 of consecutive integers from 1 to @var{n}, where @var{n} is the numeric | 19619 of consecutive integers from 1 to @var{n}, where @var{n} is the numeric |
19632 prefix argument. If you do not provide a prefix argument, you will be | 19620 prefix argument. If you do not provide a prefix argument, you will be |
19633 prompted to enter a suitable number. If @var{n} is negative, the result | 19621 prompted to enter a suitable number. If @var{n} is negative, the result |
19634 is a vector of negative integers from @var{n} to @i{-1}. | 19622 is a vector of negative integers from @var{n} to @mathit{-1}. |
19635 | 19623 |
19636 With a prefix argument of just @kbd{C-u}, the @kbd{v x} command takes | 19624 With a prefix argument of just @kbd{C-u}, the @kbd{v x} command takes |
19637 three values from the stack: @var{n}, @var{start}, and @var{incr} (with | 19625 three values from the stack: @var{n}, @var{start}, and @var{incr} (with |
19638 @var{incr} at top-of-stack). Counting starts at @var{start} and increases | 19626 @var{incr} at top-of-stack). Counting starts at @var{start} and increases |
19639 by @var{incr} for successive vector elements. If @var{start} or @var{n} | 19627 by @var{incr} for successive vector elements. If @var{start} or @var{n} |
19822 @tindex mdims | 19810 @tindex mdims |
19823 With the Hyperbolic flag, @kbd{H v l} [@code{mdims}] computes a vector | 19811 With the Hyperbolic flag, @kbd{H v l} [@code{mdims}] computes a vector |
19824 of the dimensions of a vector, matrix, or higher-order object. For | 19812 of the dimensions of a vector, matrix, or higher-order object. For |
19825 example, @samp{mdims([[a,b,c],[d,e,f]])} returns @samp{[2, 3]} since | 19813 example, @samp{mdims([[a,b,c],[d,e,f]])} returns @samp{[2, 3]} since |
19826 its argument is a | 19814 its argument is a |
19827 @texline @tmath{2\times3} | 19815 @texline @math{2\times3} |
19828 @infoline 2x3 | 19816 @infoline 2x3 |
19829 matrix. | 19817 matrix. |
19830 | 19818 |
19831 @kindex v f | 19819 @kindex v f |
19832 @pindex calc-vector-find | 19820 @pindex calc-vector-find |
19854 If the number of columns does not evenly divide the number of elements | 19842 If the number of columns does not evenly divide the number of elements |
19855 in the vector, the last row will be short and the result will not be | 19843 in the vector, the last row will be short and the result will not be |
19856 suitable for use as a matrix. For example, with the matrix | 19844 suitable for use as a matrix. For example, with the matrix |
19857 @samp{[[1, 2], @w{[3, 4]}]} on the stack, @kbd{v a 4} produces | 19845 @samp{[[1, 2], @w{[3, 4]}]} on the stack, @kbd{v a 4} produces |
19858 @samp{[[1, 2, 3, 4]]} (a | 19846 @samp{[[1, 2, 3, 4]]} (a |
19859 @texline @tmath{1\times4} | 19847 @texline @math{1\times4} |
19860 @infoline 1x4 | 19848 @infoline 1x4 |
19861 matrix), @kbd{v a 1} produces @samp{[[1], [2], [3], [4]]} (a | 19849 matrix), @kbd{v a 1} produces @samp{[[1], [2], [3], [4]]} (a |
19862 @texline @tmath{4\times1} | 19850 @texline @math{4\times1} |
19863 @infoline 4x1 | 19851 @infoline 4x1 |
19864 matrix), @kbd{v a 2} produces @samp{[[1, 2], [3, 4]]} (the original | 19852 matrix), @kbd{v a 2} produces @samp{[[1, 2], [3, 4]]} (the original |
19865 @texline @tmath{2\times2} | 19853 @texline @math{2\times2} |
19866 @infoline 2x2 | 19854 @infoline 2x2 |
19867 matrix), @w{@kbd{v a 3}} produces @samp{[[1, 2, 3], [4]]} (not a | 19855 matrix), @w{@kbd{v a 3}} produces @samp{[[1, 2, 3], [4]]} (not a |
19868 matrix), and @kbd{v a 0} produces the flattened list | 19856 matrix), and @kbd{v a 0} produces the flattened list |
19869 @samp{[1, 2, @w{3, 4}]}. | 19857 @samp{[1, 2, @w{3, 4}]}. |
19870 | 19858 |
20180 and only if it is in both of the input sets. Thus if the input | 20168 and only if it is in both of the input sets. Thus if the input |
20181 sets are disjoint, i.e., if they share no common elements, the result | 20169 sets are disjoint, i.e., if they share no common elements, the result |
20182 will be the empty vector @samp{[]}. Note that the characters @kbd{V} | 20170 will be the empty vector @samp{[]}. Note that the characters @kbd{V} |
20183 and @kbd{^} were chosen to be close to the conventional mathematical | 20171 and @kbd{^} were chosen to be close to the conventional mathematical |
20184 notation for set | 20172 notation for set |
20185 @texline union@tie{}(@tmath{A \cup B}) | 20173 @texline union@tie{}(@math{A \cup B}) |
20186 @infoline union | 20174 @infoline union |
20187 and | 20175 and |
20188 @texline intersection@tie{}(@tmath{A \cap B}). | 20176 @texline intersection@tie{}(@math{A \cap B}). |
20189 @infoline intersection. | 20177 @infoline intersection. |
20190 | 20178 |
20191 @kindex V - | 20179 @kindex V - |
20192 @pindex calc-set-difference | 20180 @pindex calc-set-difference |
20193 @tindex vdiff | 20181 @tindex vdiff |
20292 the same set. The set may include positive infinity, but must | 20280 the same set. The set may include positive infinity, but must |
20293 not include any negative numbers. The input is interpreted as a | 20281 not include any negative numbers. The input is interpreted as a |
20294 set of integers in the sense of @kbd{V F} (@code{vfloor}). Beware | 20282 set of integers in the sense of @kbd{V F} (@code{vfloor}). Beware |
20295 that a simple input like @samp{[100]} can result in a huge integer | 20283 that a simple input like @samp{[100]} can result in a huge integer |
20296 representation | 20284 representation |
20297 @texline (@tmath{2^{100}}, a 31-digit integer, in this case). | 20285 @texline (@math{2^{100}}, a 31-digit integer, in this case). |
20298 @infoline (@expr{2^100}, a 31-digit integer, in this case). | 20286 @infoline (@expr{2^100}, a 31-digit integer, in this case). |
20299 | 20287 |
20300 @node Statistical Operations, Reducing and Mapping, Set Operations, Matrix Functions | 20288 @node Statistical Operations, Reducing and Mapping, Set Operations, Matrix Functions |
20301 @section Statistical Operations on Vectors | 20289 @section Statistical Operations on Vectors |
20302 | 20290 |
20404 @tindex vmean | 20392 @tindex vmean |
20405 @cindex Mean of data values | 20393 @cindex Mean of data values |
20406 The @kbd{u M} (@code{calc-vector-mean}) [@code{vmean}] command | 20394 The @kbd{u M} (@code{calc-vector-mean}) [@code{vmean}] command |
20407 computes the average (arithmetic mean) of the data values. | 20395 computes the average (arithmetic mean) of the data values. |
20408 If the inputs are error forms | 20396 If the inputs are error forms |
20409 @texline @tmath{x \pm \sigma}, | 20397 @texline @math{x \pm \sigma}, |
20410 @infoline @samp{x +/- s}, | 20398 @infoline @samp{x +/- s}, |
20411 this is the weighted mean of the @expr{x} values with weights | 20399 this is the weighted mean of the @expr{x} values with weights |
20412 @texline @tmath{1 /\sigma^2}. | 20400 @texline @math{1 /\sigma^2}. |
20413 @infoline @expr{1 / s^2}. | 20401 @infoline @expr{1 / s^2}. |
20414 @tex | 20402 @tex |
20415 \turnoffactive | 20403 \turnoffactive |
20416 $$ \mu = { \displaystyle \sum { x_i \over \sigma_i^2 } \over | 20404 $$ \mu = { \displaystyle \sum { x_i \over \sigma_i^2 } \over |
20417 \displaystyle \sum { 1 \over \sigma_i^2 } } $$ | 20405 \displaystyle \sum { 1 \over \sigma_i^2 } } $$ |
20419 If the inputs are not error forms, this is simply the sum of the | 20407 If the inputs are not error forms, this is simply the sum of the |
20420 values divided by the count of the values. | 20408 values divided by the count of the values. |
20421 | 20409 |
20422 Note that a plain number can be considered an error form with | 20410 Note that a plain number can be considered an error form with |
20423 error | 20411 error |
20424 @texline @tmath{\sigma = 0}. | 20412 @texline @math{\sigma = 0}. |
20425 @infoline @expr{s = 0}. | 20413 @infoline @expr{s = 0}. |
20426 If the input to @kbd{u M} is a mixture of | 20414 If the input to @kbd{u M} is a mixture of |
20427 plain numbers and error forms, the result is the mean of the | 20415 plain numbers and error forms, the result is the mean of the |
20428 plain numbers, ignoring all values with non-zero errors. (By the | 20416 plain numbers, ignoring all values with non-zero errors. (By the |
20429 above definitions it's clear that a plain number effectively | 20417 above definitions it's clear that a plain number effectively |
20528 @tindex vsdev | 20516 @tindex vsdev |
20529 @cindex Standard deviation | 20517 @cindex Standard deviation |
20530 @cindex Sample statistics | 20518 @cindex Sample statistics |
20531 The @kbd{u S} (@code{calc-vector-sdev}) [@code{vsdev}] command | 20519 The @kbd{u S} (@code{calc-vector-sdev}) [@code{vsdev}] command |
20532 computes the standard | 20520 computes the standard |
20533 @texline deviation@tie{}@tmath{\sigma} | 20521 @texline deviation@tie{}@math{\sigma} |
20534 @infoline deviation | 20522 @infoline deviation |
20535 of the data values. If the values are error forms, the errors are used | 20523 of the data values. If the values are error forms, the errors are used |
20536 as weights just as for @kbd{u M}. This is the @emph{sample} standard | 20524 as weights just as for @kbd{u M}. This is the @emph{sample} standard |
20537 deviation, whose value is the square root of the sum of the squares of | 20525 deviation, whose value is the square root of the sum of the squares of |
20538 the differences between the values and the mean of the @expr{N} values, | 20526 the differences between the values and the mean of the @expr{N} values, |
20544 | 20532 |
20545 This function also applies to distributions. The standard deviation | 20533 This function also applies to distributions. The standard deviation |
20546 of a single error form is simply the error part. The standard deviation | 20534 of a single error form is simply the error part. The standard deviation |
20547 of a continuous interval happens to equal the difference between the | 20535 of a continuous interval happens to equal the difference between the |
20548 limits, divided by | 20536 limits, divided by |
20549 @texline @tmath{\sqrt{12}}. | 20537 @texline @math{\sqrt{12}}. |
20550 @infoline @expr{sqrt(12)}. | 20538 @infoline @expr{sqrt(12)}. |
20551 The standard deviation of an integer interval is the same as the | 20539 The standard deviation of an integer interval is the same as the |
20552 standard deviation of a vector of those integers. | 20540 standard deviation of a vector of those integers. |
20553 | 20541 |
20554 @kindex I u S | 20542 @kindex I u S |
20582 @cindex Variance of data values | 20570 @cindex Variance of data values |
20583 The @kbd{H u S} (@code{calc-vector-variance}) [@code{vvar}] and | 20571 The @kbd{H u S} (@code{calc-vector-variance}) [@code{vvar}] and |
20584 @kbd{H I u S} (@code{calc-vector-pop-variance}) [@code{vpvar}] | 20572 @kbd{H I u S} (@code{calc-vector-pop-variance}) [@code{vpvar}] |
20585 commands compute the variance of the data values. The variance | 20573 commands compute the variance of the data values. The variance |
20586 is the | 20574 is the |
20587 @texline square@tie{}@tmath{\sigma^2} | 20575 @texline square@tie{}@math{\sigma^2} |
20588 @infoline square | 20576 @infoline square |
20589 of the standard deviation, i.e., the sum of the | 20577 of the standard deviation, i.e., the sum of the |
20590 squares of the deviations of the data values from the mean. | 20578 squares of the deviations of the data values from the mean. |
20591 (This definition also applies when the argument is a distribution.) | 20579 (This definition also applies when the argument is a distribution.) |
20592 | 20580 |
20606 The functions in this section take two arguments, which must be | 20594 The functions in this section take two arguments, which must be |
20607 vectors of equal size. The vectors are each flattened in the same | 20595 vectors of equal size. The vectors are each flattened in the same |
20608 way as by the single-variable statistical functions. Given a numeric | 20596 way as by the single-variable statistical functions. Given a numeric |
20609 prefix argument of 1, these functions instead take one object from | 20597 prefix argument of 1, these functions instead take one object from |
20610 the stack, which must be an | 20598 the stack, which must be an |
20611 @texline @tmath{N\times2} | 20599 @texline @math{N\times2} |
20612 @infoline Nx2 | 20600 @infoline Nx2 |
20613 matrix of data values. Once again, variable names can be used in place | 20601 matrix of data values. Once again, variable names can be used in place |
20614 of actual vectors and matrices. | 20602 of actual vectors and matrices. |
20615 | 20603 |
20616 @kindex u C | 20604 @kindex u C |
20864 | 20852 |
20865 If any argument to @kbd{V M} is a matrix, the operator is normally mapped | 20853 If any argument to @kbd{V M} is a matrix, the operator is normally mapped |
20866 across all elements of the matrix. For example, given the matrix | 20854 across all elements of the matrix. For example, given the matrix |
20867 @expr{[[1, -2, 3], [-4, 5, -6]]}, @kbd{V M A} takes six absolute values to | 20855 @expr{[[1, -2, 3], [-4, 5, -6]]}, @kbd{V M A} takes six absolute values to |
20868 produce another | 20856 produce another |
20869 @texline @tmath{3\times2} | 20857 @texline @math{3\times2} |
20870 @infoline 3x2 | 20858 @infoline 3x2 |
20871 matrix, @expr{[[1, 2, 3], [4, 5, 6]]}. | 20859 matrix, @expr{[[1, 2, 3], [4, 5, 6]]}. |
20872 | 20860 |
20873 @tindex mapr | 20861 @tindex mapr |
20874 The command @kbd{V M _} [@code{mapr}] (i.e., type an underscore at the | 20862 The command @kbd{V M _} [@code{mapr}] (i.e., type an underscore at the |
22017 If you give a numeric prefix argument of 2 to @kbd{a v}, it simplifies | 22005 If you give a numeric prefix argument of 2 to @kbd{a v}, it simplifies |
22018 as if in algebraic simplification mode. This is equivalent to typing | 22006 as if in algebraic simplification mode. This is equivalent to typing |
22019 @kbd{a s}; @pxref{Simplifying Formulas}. If you give a numeric prefix | 22007 @kbd{a s}; @pxref{Simplifying Formulas}. If you give a numeric prefix |
22020 of 3 or more, it uses extended simplification mode (@kbd{a e}). | 22008 of 3 or more, it uses extended simplification mode (@kbd{a e}). |
22021 | 22009 |
22022 If you give a negative prefix argument @i{-1}, @i{-2}, or @i{-3}, | 22010 If you give a negative prefix argument @mathit{-1}, @mathit{-2}, or @mathit{-3}, |
22023 it simplifies in the corresponding mode but only works on the top-level | 22011 it simplifies in the corresponding mode but only works on the top-level |
22024 function call of the formula. For example, @samp{(2 + 3) * (2 + 3)} will | 22012 function call of the formula. For example, @samp{(2 + 3) * (2 + 3)} will |
22025 simplify to @samp{(2 + 3)^2}, without simplifying the sub-formulas | 22013 simplify to @samp{(2 + 3)^2}, without simplifying the sub-formulas |
22026 @samp{2 + 3}. As another example, typing @kbd{V R +} to sum the vector | 22014 @samp{2 + 3}. As another example, typing @kbd{V R +} to sum the vector |
22027 @samp{[1, 2, 3, 4]} produces the formula @samp{reduce(add, [1, 2, 3, 4])} | 22015 @samp{[1, 2, 3, 4]} produces the formula @samp{reduce(add, [1, 2, 3, 4])} |
22289 cases where the order of terms in a sum is changed by the default | 22277 cases where the order of terms in a sum is changed by the default |
22290 simplifications.) | 22278 simplifications.) |
22291 | 22279 |
22292 The distributive law is used to simplify sums in some cases: | 22280 The distributive law is used to simplify sums in some cases: |
22293 @expr{a x + b x} to @expr{(a + b) x}, where @expr{a} represents | 22281 @expr{a x + b x} to @expr{(a + b) x}, where @expr{a} represents |
22294 a number or an implicit 1 or @i{-1} (as in @expr{x} or @expr{-x}) | 22282 a number or an implicit 1 or @mathit{-1} (as in @expr{x} or @expr{-x}) |
22295 and similarly for @expr{b}. Use the @kbd{a c}, @w{@kbd{a f}}, or | 22283 and similarly for @expr{b}. Use the @kbd{a c}, @w{@kbd{a f}}, or |
22296 @kbd{j M} commands to merge sums with non-numeric coefficients | 22284 @kbd{j M} commands to merge sums with non-numeric coefficients |
22297 using the distributive law. | 22285 using the distributive law. |
22298 | 22286 |
22299 The distributive law is only used for sums of two terms, or | 22287 The distributive law is only used for sums of two terms, or |
22333 @expr{(-a) (b - c)}, where @expr{-a} is a negative number, is | 22321 @expr{(-a) (b - c)}, where @expr{-a} is a negative number, is |
22334 rewritten to @expr{a (c - b)}. | 22322 rewritten to @expr{a (c - b)}. |
22335 | 22323 |
22336 The distributive law of products and powers is used for adjacent | 22324 The distributive law of products and powers is used for adjacent |
22337 terms of the product: @expr{x^a x^b} goes to | 22325 terms of the product: @expr{x^a x^b} goes to |
22338 @texline @tmath{x^{a+b}} | 22326 @texline @math{x^{a+b}} |
22339 @infoline @expr{x^(a+b)} | 22327 @infoline @expr{x^(a+b)} |
22340 where @expr{a} is a number, or an implicit 1 (as in @expr{x}), | 22328 where @expr{a} is a number, or an implicit 1 (as in @expr{x}), |
22341 or the implicit one-half of @expr{@t{sqrt}(x)}, and similarly for | 22329 or the implicit one-half of @expr{@t{sqrt}(x)}, and similarly for |
22342 @expr{b}. The result is written using @samp{sqrt} or @samp{1/sqrt} | 22330 @expr{b}. The result is written using @samp{sqrt} or @samp{1/sqrt} |
22343 if the sum of the powers is @expr{1/2} or @expr{-1/2}, respectively. | 22331 if the sum of the powers is @expr{1/2} or @expr{-1/2}, respectively. |
22344 If the sum of the powers is zero, the product is simplified to | 22332 If the sum of the powers is zero, the product is simplified to |
22345 @expr{1} or to @samp{idn(1)} if matrix mode is enabled. | 22333 @expr{1} or to @samp{idn(1)} if matrix mode is enabled. |
22346 | 22334 |
22347 The product of a negative power times anything but another negative | 22335 The product of a negative power times anything but another negative |
22348 power is changed to use division: | 22336 power is changed to use division: |
22349 @texline @tmath{x^{-2} y} | 22337 @texline @math{x^{-2} y} |
22350 @infoline @expr{x^(-2) y} | 22338 @infoline @expr{x^(-2) y} |
22351 goes to @expr{y / x^2} unless matrix mode is | 22339 goes to @expr{y / x^2} unless matrix mode is |
22352 in effect and neither @expr{x} nor @expr{y} are scalar (in which | 22340 in effect and neither @expr{x} nor @expr{y} are scalar (in which |
22353 case it is considered unsafe to rearrange the order of the terms). | 22341 case it is considered unsafe to rearrange the order of the terms). |
22354 | 22342 |
22368 The quotient @expr{x / 0} is left unsimplified or changed to an | 22356 The quotient @expr{x / 0} is left unsimplified or changed to an |
22369 infinite quantity, as directed by the current infinite mode. | 22357 infinite quantity, as directed by the current infinite mode. |
22370 @xref{Infinite Mode}. | 22358 @xref{Infinite Mode}. |
22371 | 22359 |
22372 The expression | 22360 The expression |
22373 @texline @tmath{a / b^{-c}} | 22361 @texline @math{a / b^{-c}} |
22374 @infoline @expr{a / b^(-c)} | 22362 @infoline @expr{a / b^(-c)} |
22375 is changed to @expr{a b^c}, where @expr{-c} is any negative-looking | 22363 is changed to @expr{a b^c}, where @expr{-c} is any negative-looking |
22376 power. Also, @expr{1 / b^c} is changed to | 22364 power. Also, @expr{1 / b^c} is changed to |
22377 @texline @tmath{b^{-c}} | 22365 @texline @math{b^{-c}} |
22378 @infoline @expr{b^(-c)} | 22366 @infoline @expr{b^(-c)} |
22379 for any power @expr{c}. | 22367 for any power @expr{c}. |
22380 | 22368 |
22381 Also, @expr{(-a) / b} and @expr{a / (-b)} go to @expr{-(a/b)}; | 22369 Also, @expr{(-a) / b} and @expr{a / (-b)} go to @expr{-(a/b)}; |
22382 @expr{(a/b) / c} goes to @expr{a / (b c)}; and @expr{a / (b/c)} | 22370 @expr{(a/b) / c} goes to @expr{a / (b c)}; and @expr{a / (b/c)} |
22413 | 22401 |
22414 Powers of products or quotients @expr{(a b)^c}, @expr{(a/b)^c} | 22402 Powers of products or quotients @expr{(a b)^c}, @expr{(a/b)^c} |
22415 are distributed to @expr{a^c b^c}, @expr{a^c / b^c} only if @expr{c} | 22403 are distributed to @expr{a^c b^c}, @expr{a^c / b^c} only if @expr{c} |
22416 is an integer, or if either @expr{a} or @expr{b} are nonnegative | 22404 is an integer, or if either @expr{a} or @expr{b} are nonnegative |
22417 real numbers. Powers of powers @expr{(a^b)^c} are simplified to | 22405 real numbers. Powers of powers @expr{(a^b)^c} are simplified to |
22418 @texline @tmath{a^{b c}} | 22406 @texline @math{a^{b c}} |
22419 @infoline @expr{a^(b c)} | 22407 @infoline @expr{a^(b c)} |
22420 only when @expr{c} is an integer and @expr{b c} also | 22408 only when @expr{c} is an integer and @expr{b c} also |
22421 evaluates to an integer. Without these restrictions these simplifications | 22409 evaluates to an integer. Without these restrictions these simplifications |
22422 would not be safe because of problems with principal values. | 22410 would not be safe because of problems with principal values. |
22423 (In other words, | 22411 (In other words, |
22424 @texline @tmath{((-3)^{1/2})^2} | 22412 @texline @math{((-3)^{1/2})^2} |
22425 @infoline @expr{((-3)^1:2)^2} | 22413 @infoline @expr{((-3)^1:2)^2} |
22426 is safe to simplify, but | 22414 is safe to simplify, but |
22427 @texline @tmath{((-3)^2)^{1/2}} | 22415 @texline @math{((-3)^2)^{1/2}} |
22428 @infoline @expr{((-3)^2)^1:2} | 22416 @infoline @expr{((-3)^2)^1:2} |
22429 is not.) @xref{Declarations}, for ways to inform Calc that your | 22417 is not.) @xref{Declarations}, for ways to inform Calc that your |
22430 variables satisfy these requirements. | 22418 variables satisfy these requirements. |
22431 | 22419 |
22432 As a special case of this rule, @expr{@t{sqrt}(x)^n} is simplified to | 22420 As a special case of this rule, @expr{@t{sqrt}(x)^n} is simplified to |
22433 @texline @tmath{x^{n/2}} | 22421 @texline @math{x^{n/2}} |
22434 @infoline @expr{x^(n/2)} | 22422 @infoline @expr{x^(n/2)} |
22435 only for even integers @expr{n}. | 22423 only for even integers @expr{n}. |
22436 | 22424 |
22437 If @expr{a} is known to be real, @expr{b} is an even integer, and | 22425 If @expr{a} is known to be real, @expr{b} is an even integer, and |
22438 @expr{c} is a half- or quarter-integer, then @expr{(a^b)^c} is | 22426 @expr{c} is a half- or quarter-integer, then @expr{(a^b)^c} is |
22441 Also, @expr{(-a)^b} is simplified to @expr{a^b} if @expr{b} is an | 22429 Also, @expr{(-a)^b} is simplified to @expr{a^b} if @expr{b} is an |
22442 even integer, or to @expr{-(a^b)} if @expr{b} is an odd integer, | 22430 even integer, or to @expr{-(a^b)} if @expr{b} is an odd integer, |
22443 for any negative-looking expression @expr{-a}. | 22431 for any negative-looking expression @expr{-a}. |
22444 | 22432 |
22445 Square roots @expr{@t{sqrt}(x)} generally act like one-half powers | 22433 Square roots @expr{@t{sqrt}(x)} generally act like one-half powers |
22446 @texline @tmath{x^{1:2}} | 22434 @texline @math{x^{1:2}} |
22447 @infoline @expr{x^1:2} | 22435 @infoline @expr{x^1:2} |
22448 for the purposes of the above-listed simplifications. | 22436 for the purposes of the above-listed simplifications. |
22449 | 22437 |
22450 Also, note that | 22438 Also, note that |
22451 @texline @tmath{1 / x^{1:2}} | 22439 @texline @math{1 / x^{1:2}} |
22452 @infoline @expr{1 / x^1:2} | 22440 @infoline @expr{1 / x^1:2} |
22453 is changed to | 22441 is changed to |
22454 @texline @tmath{x^{-1:2}}, | 22442 @texline @math{x^{-1:2}}, |
22455 @infoline @expr{x^(-1:2)}, | 22443 @infoline @expr{x^(-1:2)}, |
22456 but @expr{1 / @t{sqrt}(x)} is left alone. | 22444 but @expr{1 / @t{sqrt}(x)} is left alone. |
22457 | 22445 |
22458 @tex | 22446 @tex |
22459 \bigskip | 22447 \bigskip |
22592 taken into account when terms of a product are being compared. | 22580 taken into account when terms of a product are being compared. |
22593 Thus @expr{(x + y) (y + x)} will be simplified to @expr{(x + y)^2}. | 22581 Thus @expr{(x + y) (y + x)} will be simplified to @expr{(x + y)^2}. |
22594 A subtle point is that @expr{(x - y) (y - x)} will @emph{not} | 22582 A subtle point is that @expr{(x - y) (y - x)} will @emph{not} |
22595 be simplified to @expr{-(x - y)^2}; Calc does not notice that | 22583 be simplified to @expr{-(x - y)^2}; Calc does not notice that |
22596 one term can be written as a constant times the other, even if | 22584 one term can be written as a constant times the other, even if |
22597 that constant is @i{-1}. | 22585 that constant is @mathit{-1}. |
22598 | 22586 |
22599 A fraction times any expression, @expr{(a:b) x}, is changed to | 22587 A fraction times any expression, @expr{(a:b) x}, is changed to |
22600 a quotient involving integers: @expr{a x / b}. This is not | 22588 a quotient involving integers: @expr{a x / b}. This is not |
22601 done for floating-point numbers like @expr{0.5}, however. This | 22589 done for floating-point numbers like @expr{0.5}, however. This |
22602 is one reason why you may find it convenient to turn Fraction mode | 22590 is one reason why you may find it convenient to turn Fraction mode |
22635 | 22623 |
22636 Square roots of integer or rational arguments are simplified in | 22624 Square roots of integer or rational arguments are simplified in |
22637 several ways. (Note that these will be left unevaluated only in | 22625 several ways. (Note that these will be left unevaluated only in |
22638 Symbolic mode.) First, square integer or rational factors are | 22626 Symbolic mode.) First, square integer or rational factors are |
22639 pulled out so that @expr{@t{sqrt}(8)} is rewritten as | 22627 pulled out so that @expr{@t{sqrt}(8)} is rewritten as |
22640 @texline @tmath{$2\,\t{sqrt}(2)$}. | 22628 @texline @math{2\,\t{sqrt}(2)}. |
22641 @infoline @expr{2 sqrt(2)}. | 22629 @infoline @expr{2 sqrt(2)}. |
22642 Conceptually speaking this implies factoring the argument into primes | 22630 Conceptually speaking this implies factoring the argument into primes |
22643 and moving pairs of primes out of the square root, but for reasons of | 22631 and moving pairs of primes out of the square root, but for reasons of |
22644 efficiency Calc only looks for primes up to 29. | 22632 efficiency Calc only looks for primes up to 29. |
22645 | 22633 |
22697 No simplifications for inverse trigonometric and hyperbolic | 22685 No simplifications for inverse trigonometric and hyperbolic |
22698 functions are known, except for negative arguments of @code{arcsin}, | 22686 functions are known, except for negative arguments of @code{arcsin}, |
22699 @code{arctan}, @code{arcsinh}, and @code{arctanh}. Note that | 22687 @code{arctan}, @code{arcsinh}, and @code{arctanh}. Note that |
22700 @expr{@t{arcsin}(@t{sin}(x))} can @emph{not} safely change to | 22688 @expr{@t{arcsin}(@t{sin}(x))} can @emph{not} safely change to |
22701 @expr{x}, since this only correct within an integer multiple of | 22689 @expr{x}, since this only correct within an integer multiple of |
22702 @texline @tmath{2 \pi} | 22690 @texline @math{2 \pi} |
22703 @infoline @expr{2 pi} | 22691 @infoline @expr{2 pi} |
22704 radians or 360 degrees. However, @expr{@t{arcsinh}(@t{sinh}(x))} is | 22692 radians or 360 degrees. However, @expr{@t{arcsinh}(@t{sinh}(x))} is |
22705 simplified to @expr{x} if @expr{x} is known to be real. | 22693 simplified to @expr{x} if @expr{x} is known to be real. |
22706 | 22694 |
22707 Several simplifications that apply to logarithms and exponentials | 22695 Several simplifications that apply to logarithms and exponentials |
22708 are that @expr{@t{exp}(@t{ln}(x))}, | 22696 are that @expr{@t{exp}(@t{ln}(x))}, |
22709 @texline @t{e}@tmath{^{\ln(x)}}, | 22697 @texline @t{e}@math{^{\ln(x)}}, |
22710 @infoline @expr{e^@t{ln}(x)}, | 22698 @infoline @expr{e^@t{ln}(x)}, |
22711 and | 22699 and |
22712 @texline @tmath{10^{{\rm log10}(x)}} | 22700 @texline @math{10^{{\rm log10}(x)}} |
22713 @infoline @expr{10^@t{log10}(x)} | 22701 @infoline @expr{10^@t{log10}(x)} |
22714 all reduce to @expr{x}. Also, @expr{@t{ln}(@t{exp}(x))}, etc., can | 22702 all reduce to @expr{x}. Also, @expr{@t{ln}(@t{exp}(x))}, etc., can |
22715 reduce to @expr{x} if @expr{x} is provably real. The form | 22703 reduce to @expr{x} if @expr{x} is provably real. The form |
22716 @expr{@t{exp}(x)^y} is simplified to @expr{@t{exp}(x y)}. If @expr{x} | 22704 @expr{@t{exp}(x)^y} is simplified to @expr{@t{exp}(x y)}. If @expr{x} |
22717 is a suitable multiple of | 22705 is a suitable multiple of |
22718 @texline @tmath{\pi i} | 22706 @texline @math{\pi i} |
22719 @infoline @expr{pi i} | 22707 @infoline @expr{pi i} |
22720 (as described above for the trigonometric functions), then | 22708 (as described above for the trigonometric functions), then |
22721 @expr{@t{exp}(x)} or @expr{e^x} will be expanded. Finally, | 22709 @expr{@t{exp}(x)} or @expr{e^x} will be expanded. Finally, |
22722 @expr{@t{ln}(x)} is simplified to a form involving @code{pi} and | 22710 @expr{@t{ln}(x)} is simplified to a form involving @code{pi} and |
22723 @code{i} where @expr{x} is provably negative, positive imaginary, or | 22711 @code{i} where @expr{x} is provably negative, positive imaginary, or |
22798 values of @expr{x} in a certain range; outside that range, values | 22786 values of @expr{x} in a certain range; outside that range, values |
22799 are folded down to the 360-degree range that the inverse trigonometric | 22787 are folded down to the 360-degree range that the inverse trigonometric |
22800 functions always produce. | 22788 functions always produce. |
22801 | 22789 |
22802 Powers of powers @expr{(x^a)^b} are simplified to | 22790 Powers of powers @expr{(x^a)^b} are simplified to |
22803 @texline @tmath{x^{a b}} | 22791 @texline @math{x^{a b}} |
22804 @infoline @expr{x^(a b)} | 22792 @infoline @expr{x^(a b)} |
22805 for all @expr{a} and @expr{b}. These results will be valid only | 22793 for all @expr{a} and @expr{b}. These results will be valid only |
22806 in a restricted range of @expr{x}; for example, in | 22794 in a restricted range of @expr{x}; for example, in |
22807 @texline @tmath{(x^2)^{1:2}} | 22795 @texline @math{(x^2)^{1:2}} |
22808 @infoline @expr{(x^2)^1:2} | 22796 @infoline @expr{(x^2)^1:2} |
22809 the powers cancel to get @expr{x}, which is valid for positive values | 22797 the powers cancel to get @expr{x}, which is valid for positive values |
22810 of @expr{x} but not for negative or complex values. | 22798 of @expr{x} but not for negative or complex values. |
22811 | 22799 |
22812 Similarly, @expr{@t{sqrt}(x^a)} and @expr{@t{sqrt}(x)^a} are both | 22800 Similarly, @expr{@t{sqrt}(x^a)} and @expr{@t{sqrt}(x)^a} are both |
22813 simplified (possibly unsafely) to | 22801 simplified (possibly unsafely) to |
22814 @texline @tmath{x^{a/2}}. | 22802 @texline @math{x^{a/2}}. |
22815 @infoline @expr{x^(a/2)}. | 22803 @infoline @expr{x^(a/2)}. |
22816 | 22804 |
22817 Forms like @expr{@t{sqrt}(1 - sin(x)^2)} are simplified to, e.g., | 22805 Forms like @expr{@t{sqrt}(1 - sin(x)^2)} are simplified to, e.g., |
22818 @expr{@t{cos}(x)}. Calc has identities of this sort for @code{sin}, | 22806 @expr{@t{cos}(x)}. Calc has identities of this sort for @code{sin}, |
22819 @code{cos}, @code{tan}, @code{sinh}, and @code{cosh}. | 22807 @code{cos}, @code{tan}, @code{sinh}, and @code{cosh}. |
22885 number for an answer, then the quotient simplifies to that number. | 22873 number for an answer, then the quotient simplifies to that number. |
22886 | 22874 |
22887 For powers and square roots, the ``unsafe'' simplifications | 22875 For powers and square roots, the ``unsafe'' simplifications |
22888 @expr{(a b)^c} to @expr{a^c b^c}, @expr{(a/b)^c} to @expr{a^c / b^c}, | 22876 @expr{(a b)^c} to @expr{a^c b^c}, @expr{(a/b)^c} to @expr{a^c / b^c}, |
22889 and @expr{(a^b)^c} to | 22877 and @expr{(a^b)^c} to |
22890 @texline @tmath{a^{b c}} | 22878 @texline @math{a^{b c}} |
22891 @infoline @expr{a^(b c)} | 22879 @infoline @expr{a^(b c)} |
22892 are done if the powers are real numbers. (These are safe in the context | 22880 are done if the powers are real numbers. (These are safe in the context |
22893 of units because all numbers involved can reasonably be assumed to be | 22881 of units because all numbers involved can reasonably be assumed to be |
22894 real.) | 22882 real.) |
22895 | 22883 |
22900 according to the previous paragraph. For example, @samp{acre^1.5} | 22888 according to the previous paragraph. For example, @samp{acre^1.5} |
22901 is simplified by noting that @expr{1.5 = 3:2}, that @samp{acre} | 22889 is simplified by noting that @expr{1.5 = 3:2}, that @samp{acre} |
22902 is defined in terms of @samp{m^2}, and that the 2 in the power of | 22890 is defined in terms of @samp{m^2}, and that the 2 in the power of |
22903 @code{m} is a multiple of 2 in @expr{3:2}. Thus, @code{acre^1.5} is | 22891 @code{m} is a multiple of 2 in @expr{3:2}. Thus, @code{acre^1.5} is |
22904 replaced by approximately | 22892 replaced by approximately |
22905 @texline @tmath{(4046 m^2)^{1.5}} | 22893 @texline @math{(4046 m^2)^{1.5}} |
22906 @infoline @expr{(4046 m^2)^1.5}, | 22894 @infoline @expr{(4046 m^2)^1.5}, |
22907 which is then changed to | 22895 which is then changed to |
22908 @texline @tmath{4046^{1.5} \, (m^2)^{1.5}}, | 22896 @texline @math{4046^{1.5} \, (m^2)^{1.5}}, |
22909 @infoline @expr{4046^1.5 (m^2)^1.5}, | 22897 @infoline @expr{4046^1.5 (m^2)^1.5}, |
22910 then to @expr{257440 m^3}. | 22898 then to @expr{257440 m^3}. |
22911 | 22899 |
22912 The functions @code{float}, @code{frac}, @code{clean}, @code{abs}, | 22900 The functions @code{float}, @code{frac}, @code{clean}, @code{abs}, |
22913 as well as @code{floor} and the other integer truncation functions, | 22901 as well as @code{floor} and the other integer truncation functions, |
23193 answer! | 23181 answer! |
23194 | 23182 |
23195 If you use the @code{deriv} function directly in an algebraic formula, | 23183 If you use the @code{deriv} function directly in an algebraic formula, |
23196 you can write @samp{deriv(f,x,x0)} which represents the derivative | 23184 you can write @samp{deriv(f,x,x0)} which represents the derivative |
23197 of @expr{f} with respect to @expr{x}, evaluated at the point | 23185 of @expr{f} with respect to @expr{x}, evaluated at the point |
23198 @texline @tmath{x=x_0}. | 23186 @texline @math{x=x_0}. |
23199 @infoline @expr{x=x0}. | 23187 @infoline @expr{x=x0}. |
23200 | 23188 |
23201 If the formula being differentiated contains functions which Calc does | 23189 If the formula being differentiated contains functions which Calc does |
23202 not know, the derivatives of those functions are produced by adding | 23190 not know, the derivatives of those functions are produced by adding |
23203 primes (apostrophe characters). For example, @samp{deriv(f(2x), x)} | 23191 primes (apostrophe characters). For example, @samp{deriv(f(2x), x)} |
23233 respect to a variable. The integrator is not guaranteed to work for | 23221 respect to a variable. The integrator is not guaranteed to work for |
23234 all integrable functions, but it is able to integrate several large | 23222 all integrable functions, but it is able to integrate several large |
23235 classes of formulas. In particular, any polynomial or rational function | 23223 classes of formulas. In particular, any polynomial or rational function |
23236 (a polynomial divided by a polynomial) is acceptable. (Rational functions | 23224 (a polynomial divided by a polynomial) is acceptable. (Rational functions |
23237 don't have to be in explicit quotient form, however; | 23225 don't have to be in explicit quotient form, however; |
23238 @texline @tmath{x/(1+x^{-2})} | 23226 @texline @math{x/(1+x^{-2})} |
23239 @infoline @expr{x/(1+x^-2)} | 23227 @infoline @expr{x/(1+x^-2)} |
23240 is not strictly a quotient of polynomials, but it is equivalent to | 23228 is not strictly a quotient of polynomials, but it is equivalent to |
23241 @expr{x^3/(x^2+1)}, which is.) Also, square roots of terms involving | 23229 @expr{x^3/(x^2+1)}, which is.) Also, square roots of terms involving |
23242 @expr{x} and @expr{x^2} may appear in rational functions being | 23230 @expr{x} and @expr{x^2} may appear in rational functions being |
23243 integrated. Finally, rational functions involving trigonometric or | 23231 integrated. Finally, rational functions involving trigonometric or |
23259 @end tex | 23247 @end tex |
23260 | 23248 |
23261 Please note that the current implementation of Calc's integrator sometimes | 23249 Please note that the current implementation of Calc's integrator sometimes |
23262 produces results that are significantly more complex than they need to | 23250 produces results that are significantly more complex than they need to |
23263 be. For example, the integral Calc finds for | 23251 be. For example, the integral Calc finds for |
23264 @texline @tmath{1/(x+\sqrt{x^2+1})} | 23252 @texline @math{1/(x+\sqrt{x^2+1})} |
23265 @infoline @expr{1/(x+sqrt(x^2+1))} | 23253 @infoline @expr{1/(x+sqrt(x^2+1))} |
23266 is several times more complicated than the answer Mathematica | 23254 is several times more complicated than the answer Mathematica |
23267 returns for the same input, although the two forms are numerically | 23255 returns for the same input, although the two forms are numerically |
23268 equivalent. Also, any indefinite integral should be considered to have | 23256 equivalent. Also, any indefinite integral should be considered to have |
23269 an arbitrary constant of integration added to it, although Calc does not | 23257 an arbitrary constant of integration added to it, although Calc does not |
23270 write an explicit constant of integration in its result. For example, | 23258 write an explicit constant of integration in its result. For example, |
23271 Calc's solution for | 23259 Calc's solution for |
23272 @texline @tmath{1/(1+\tan x)} | 23260 @texline @math{1/(1+\tan x)} |
23273 @infoline @expr{1/(1+tan(x))} | 23261 @infoline @expr{1/(1+tan(x))} |
23274 differs from the solution given in the @emph{CRC Math Tables} by a | 23262 differs from the solution given in the @emph{CRC Math Tables} by a |
23275 constant factor of | 23263 constant factor of |
23276 @texline @tmath{\pi i / 2} | 23264 @texline @math{\pi i / 2} |
23277 @infoline @expr{pi i / 2}, | 23265 @infoline @expr{pi i / 2}, |
23278 due to a different choice of constant of integration. | 23266 due to a different choice of constant of integration. |
23279 | 23267 |
23280 The Calculator remembers all the integrals it has done. If conditions | 23268 The Calculator remembers all the integrals it has done. If conditions |
23281 change in a way that would invalidate the old integrals, say, a switch | 23269 change in a way that would invalidate the old integrals, say, a switch |
23331 @end ignore | 23319 @end ignore |
23332 @tindex Ei | 23320 @tindex Ei |
23333 As a more serious example, the expression @samp{exp(x)/x} cannot be | 23321 As a more serious example, the expression @samp{exp(x)/x} cannot be |
23334 integrated in terms of the standard functions, so the ``exponential | 23322 integrated in terms of the standard functions, so the ``exponential |
23335 integral'' function | 23323 integral'' function |
23336 @texline @tmath{{\rm Ei}(x)} | 23324 @texline @math{{\rm Ei}(x)} |
23337 @infoline @expr{Ei(x)} | 23325 @infoline @expr{Ei(x)} |
23338 was invented to describe it. | 23326 was invented to describe it. |
23339 We can get Calc to do this integral in terms of a made-up @code{Ei} | 23327 We can get Calc to do this integral in terms of a made-up @code{Ei} |
23340 function by adding the rule @samp{[integtry(exp(x)/x, x) := Ei(x)]} | 23328 function by adding the rule @samp{[integtry(exp(x)/x, x) := Ei(x)]} |
23341 to @code{IntegRules}. Now entering @samp{exp(2x)/x} on the stack | 23329 to @code{IntegRules}. Now entering @samp{exp(2x)/x} on the stack |
23504 form @expr{X = 0}. | 23492 form @expr{X = 0}. |
23505 | 23493 |
23506 This command also works for inequalities, as in @expr{y < 3x + 6}. | 23494 This command also works for inequalities, as in @expr{y < 3x + 6}. |
23507 Some inequalities cannot be solved where the analogous equation could | 23495 Some inequalities cannot be solved where the analogous equation could |
23508 be; for example, solving | 23496 be; for example, solving |
23509 @texline @tmath{a < b \, c} | 23497 @texline @math{a < b \, c} |
23510 @infoline @expr{a < b c} | 23498 @infoline @expr{a < b c} |
23511 for @expr{b} is impossible | 23499 for @expr{b} is impossible |
23512 without knowing the sign of @expr{c}. In this case, @kbd{a S} will | 23500 without knowing the sign of @expr{c}. In this case, @kbd{a S} will |
23513 produce the result | 23501 produce the result |
23514 @texline @tmath{b \mathbin{\hbox{\code{!=}}} a/c} | 23502 @texline @math{b \mathbin{\hbox{\code{!=}}} a/c} |
23515 @infoline @expr{b != a/c} | 23503 @infoline @expr{b != a/c} |
23516 (using the not-equal-to operator) to signify that the direction of the | 23504 (using the not-equal-to operator) to signify that the direction of the |
23517 inequality is now unknown. The inequality | 23505 inequality is now unknown. The inequality |
23518 @texline @tmath{a \le b \, c} | 23506 @texline @math{a \le b \, c} |
23519 @infoline @expr{a <= b c} | 23507 @infoline @expr{a <= b c} |
23520 is not even partially solved. @xref{Declarations}, for a way to tell | 23508 is not even partially solved. @xref{Declarations}, for a way to tell |
23521 Calc that the signs of the variables in a formula are in fact known. | 23509 Calc that the signs of the variables in a formula are in fact known. |
23522 | 23510 |
23523 Two useful commands for working with the result of @kbd{a S} are | 23511 Two useful commands for working with the result of @kbd{a S} are |
23540 Some equations have more than one solution. The Hyperbolic flag | 23528 Some equations have more than one solution. The Hyperbolic flag |
23541 (@code{H a S}) [@code{fsolve}] tells the solver to report the fully | 23529 (@code{H a S}) [@code{fsolve}] tells the solver to report the fully |
23542 general family of solutions. It will invent variables @code{n1}, | 23530 general family of solutions. It will invent variables @code{n1}, |
23543 @code{n2}, @dots{}, which represent independent arbitrary integers, and | 23531 @code{n2}, @dots{}, which represent independent arbitrary integers, and |
23544 @code{s1}, @code{s2}, @dots{}, which represent independent arbitrary | 23532 @code{s1}, @code{s2}, @dots{}, which represent independent arbitrary |
23545 signs (either @i{+1} or @i{-1}). If you don't use the Hyperbolic | 23533 signs (either @mathit{+1} or @mathit{-1}). If you don't use the Hyperbolic |
23546 flag, Calc will use zero in place of all arbitrary integers, and plus | 23534 flag, Calc will use zero in place of all arbitrary integers, and plus |
23547 one in place of all arbitrary signs. Note that variables like @code{n1} | 23535 one in place of all arbitrary signs. Note that variables like @code{n1} |
23548 and @code{s1} are not given any special interpretation in Calc except by | 23536 and @code{s1} are not given any special interpretation in Calc except by |
23549 the equation solver itself. As usual, you can use the @w{@kbd{s l}} | 23537 the equation solver itself. As usual, you can use the @w{@kbd{s l}} |
23550 (@code{calc-let}) command to obtain solutions for various actual values | 23538 (@code{calc-let}) command to obtain solutions for various actual values |
23973 value of the variable which minimizes the formula's value, along | 23961 value of the variable which minimizes the formula's value, along |
23974 with the minimum value itself. | 23962 with the minimum value itself. |
23975 | 23963 |
23976 Note that this command looks for a @emph{local} minimum. Many functions | 23964 Note that this command looks for a @emph{local} minimum. Many functions |
23977 have more than one minimum; some, like | 23965 have more than one minimum; some, like |
23978 @texline @tmath{x \sin x}, | 23966 @texline @math{x \sin x}, |
23979 @infoline @expr{x sin(x)}, | 23967 @infoline @expr{x sin(x)}, |
23980 have infinitely many. In fact, there is no easy way to define the | 23968 have infinitely many. In fact, there is no easy way to define the |
23981 ``global'' minimum of | 23969 ``global'' minimum of |
23982 @texline @tmath{x \sin x} | 23970 @texline @math{x \sin x} |
23983 @infoline @expr{x sin(x)} | 23971 @infoline @expr{x sin(x)} |
23984 but Calc can still locate any particular local minimum | 23972 but Calc can still locate any particular local minimum |
23985 for you. Calc basically goes downhill from the initial guess until it | 23973 for you. Calc basically goes downhill from the initial guess until it |
23986 finds a point at which the function's value is greater both to the left | 23974 finds a point at which the function's value is greater both to the left |
23987 and to the right. Calc does not use derivatives when minimizing a function. | 23975 and to the right. Calc does not use derivatives when minimizing a function. |
24100 the @dfn{parameters} of the model. | 24088 the @dfn{parameters} of the model. |
24101 | 24089 |
24102 The @kbd{a F} command takes the data set to be fitted from the stack. | 24090 The @kbd{a F} command takes the data set to be fitted from the stack. |
24103 By default, it expects the data in the form of a matrix. For example, | 24091 By default, it expects the data in the form of a matrix. For example, |
24104 for a linear or polynomial fit, this would be a | 24092 for a linear or polynomial fit, this would be a |
24105 @texline @tmath{2\times N} | 24093 @texline @math{2\times N} |
24106 @infoline 2xN | 24094 @infoline 2xN |
24107 matrix where the first row is a list of @expr{x} values and the second | 24095 matrix where the first row is a list of @expr{x} values and the second |
24108 row has the corresponding @expr{y} values. For the multilinear fit | 24096 row has the corresponding @expr{y} values. For the multilinear fit |
24109 shown above, the matrix would have four rows (@expr{x_1}, @expr{x_2}, | 24097 shown above, the matrix would have four rows (@expr{x_1}, @expr{x_2}, |
24110 @expr{x_3}, and @expr{y}, respectively). | 24098 @expr{x_3}, and @expr{y}, respectively). |
24111 | 24099 |
24112 If you happen to have an | 24100 If you happen to have an |
24113 @texline @tmath{N\times2} | 24101 @texline @math{N\times2} |
24114 @infoline Nx2 | 24102 @infoline Nx2 |
24115 matrix instead of a | 24103 matrix instead of a |
24116 @texline @tmath{2\times N} | 24104 @texline @math{2\times N} |
24117 @infoline 2xN | 24105 @infoline 2xN |
24118 matrix, just press @kbd{v t} first to transpose the matrix. | 24106 matrix, just press @kbd{v t} first to transpose the matrix. |
24119 | 24107 |
24120 After you type @kbd{a F}, Calc prompts you to select a model. For a | 24108 After you type @kbd{a F}, Calc prompts you to select a model. For a |
24121 linear fit, press the digit @kbd{1}. | 24109 linear fit, press the digit @kbd{1}. |
24209 @noindent | 24197 @noindent |
24210 which is clearly zero if @expr{a + b x} exactly fits all data points, | 24198 which is clearly zero if @expr{a + b x} exactly fits all data points, |
24211 and increases as various @expr{a + b x_i} values fail to match the | 24199 and increases as various @expr{a + b x_i} values fail to match the |
24212 corresponding @expr{y_i} values. There are several reasons why the | 24200 corresponding @expr{y_i} values. There are several reasons why the |
24213 summand is squared, one of them being to ensure that | 24201 summand is squared, one of them being to ensure that |
24214 @texline @tmath{\chi^2 \ge 0}. | 24202 @texline @math{\chi^2 \ge 0}. |
24215 @infoline @expr{chi^2 >= 0}. | 24203 @infoline @expr{chi^2 >= 0}. |
24216 Least-squares fitting simply chooses the values of @expr{a} and @expr{b} | 24204 Least-squares fitting simply chooses the values of @expr{a} and @expr{b} |
24217 for which the error | 24205 for which the error |
24218 @texline @tmath{\chi^2} | 24206 @texline @math{\chi^2} |
24219 @infoline @expr{chi^2} | 24207 @infoline @expr{chi^2} |
24220 is as small as possible. | 24208 is as small as possible. |
24221 | 24209 |
24222 Other kinds of models do the same thing but with a different model | 24210 Other kinds of models do the same thing but with a different model |
24223 formula in place of @expr{a + b x_i}. | 24211 formula in place of @expr{a + b x_i}. |
24269 0.142857142855 x^2 + 1.34285714287 x + 3.59999999998 | 24257 0.142857142855 x^2 + 1.34285714287 x + 3.59999999998 |
24270 @end example | 24258 @end example |
24271 | 24259 |
24272 An important result from the theory of polynomial fitting is that it | 24260 An important result from the theory of polynomial fitting is that it |
24273 is always possible to fit @var{n} data points exactly using a polynomial | 24261 is always possible to fit @var{n} data points exactly using a polynomial |
24274 of degree @i{@var{n}-1}, sometimes called an @dfn{interpolating polynomial}. | 24262 of degree @mathit{@var{n}-1}, sometimes called an @dfn{interpolating polynomial}. |
24275 Using the modified (14) data matrix, a model number of 4 gives | 24263 Using the modified (14) data matrix, a model number of 4 gives |
24276 a polynomial that exactly matches all five data points: | 24264 a polynomial that exactly matches all five data points: |
24277 | 24265 |
24278 @example | 24266 @example |
24279 0.04167 x^4 - 0.4167 x^3 + 1.458 x^2 - 0.08333 x + 4. | 24267 0.04167 x^4 - 0.4167 x^3 + 1.458 x^2 - 0.08333 x + 4. |
24374 It is also possible for the @emph{input} to a fitting operation to | 24362 It is also possible for the @emph{input} to a fitting operation to |
24375 contain error forms. The data values must either all include errors | 24363 contain error forms. The data values must either all include errors |
24376 or all be plain numbers. Error forms can go anywhere but generally | 24364 or all be plain numbers. Error forms can go anywhere but generally |
24377 go on the numbers in the last row of the data matrix. If the last | 24365 go on the numbers in the last row of the data matrix. If the last |
24378 row contains error forms | 24366 row contains error forms |
24379 @texline `@var{y_i}@w{ @t{+/-} }@tmath{\sigma_i}', | 24367 @texline `@var{y_i}@w{ @t{+/-} }@math{\sigma_i}', |
24380 @infoline `@var{y_i}@w{ @t{+/-} }@var{sigma_i}', | 24368 @infoline `@var{y_i}@w{ @t{+/-} }@var{sigma_i}', |
24381 then the | 24369 then the |
24382 @texline @tmath{\chi^2} | 24370 @texline @math{\chi^2} |
24383 @infoline @expr{chi^2} | 24371 @infoline @expr{chi^2} |
24384 statistic is now, | 24372 statistic is now, |
24385 | 24373 |
24386 @ifinfo | 24374 @ifinfo |
24387 @example | 24375 @example |
24400 the fitting operation. | 24388 the fitting operation. |
24401 | 24389 |
24402 If there are error forms on other rows of the data matrix, all the | 24390 If there are error forms on other rows of the data matrix, all the |
24403 errors for a given data point are combined; the square root of the | 24391 errors for a given data point are combined; the square root of the |
24404 sum of the squares of the errors forms the | 24392 sum of the squares of the errors forms the |
24405 @texline @tmath{\sigma_i} | 24393 @texline @math{\sigma_i} |
24406 @infoline @expr{sigma_i} | 24394 @infoline @expr{sigma_i} |
24407 used for the data point. | 24395 used for the data point. |
24408 | 24396 |
24409 Both @kbd{a F} and @kbd{H a F} can accept error forms in the input | 24397 Both @kbd{a F} and @kbd{H a F} can accept error forms in the input |
24410 matrix, although if you are concerned about error analysis you will | 24398 matrix, although if you are concerned about error analysis you will |
24411 probably use @kbd{H a F} so that the output also contains error | 24399 probably use @kbd{H a F} so that the output also contains error |
24412 estimates. | 24400 estimates. |
24413 | 24401 |
24414 If the input contains error forms but all the | 24402 If the input contains error forms but all the |
24415 @texline @tmath{\sigma_i} | 24403 @texline @math{\sigma_i} |
24416 @infoline @expr{sigma_i} | 24404 @infoline @expr{sigma_i} |
24417 values are the same, it is easy to see that the resulting fitted model | 24405 values are the same, it is easy to see that the resulting fitted model |
24418 will be the same as if the input did not have error forms at all | 24406 will be the same as if the input did not have error forms at all |
24419 @texline (@tmath{\chi^2} | 24407 @texline (@math{\chi^2} |
24420 @infoline (@expr{chi^2} | 24408 @infoline (@expr{chi^2} |
24421 is simply scaled uniformly by | 24409 is simply scaled uniformly by |
24422 @texline @tmath{1 / \sigma^2}, | 24410 @texline @math{1 / \sigma^2}, |
24423 @infoline @expr{1 / sigma^2}, | 24411 @infoline @expr{1 / sigma^2}, |
24424 which doesn't affect where it has a minimum). But there @emph{will} be | 24412 which doesn't affect where it has a minimum). But there @emph{will} be |
24425 a difference in the estimated errors of the coefficients reported by | 24413 a difference in the estimated errors of the coefficients reported by |
24426 @kbd{H a F}. | 24414 @kbd{H a F}. |
24427 | 24415 |
24452 will have length @expr{M = d+1} with the constant term first. | 24440 will have length @expr{M = d+1} with the constant term first. |
24453 | 24441 |
24454 @item | 24442 @item |
24455 The covariance matrix @expr{C} computed from the fit. This is | 24443 The covariance matrix @expr{C} computed from the fit. This is |
24456 an @var{m}x@var{m} symmetric matrix; the diagonal elements | 24444 an @var{m}x@var{m} symmetric matrix; the diagonal elements |
24457 @texline @tmath{C_{jj}} | 24445 @texline @math{C_{jj}} |
24458 @infoline @expr{C_j_j} | 24446 @infoline @expr{C_j_j} |
24459 are the variances | 24447 are the variances |
24460 @texline @tmath{\sigma_j^2} | 24448 @texline @math{\sigma_j^2} |
24461 @infoline @expr{sigma_j^2} | 24449 @infoline @expr{sigma_j^2} |
24462 of the parameters. The other elements are covariances | 24450 of the parameters. The other elements are covariances |
24463 @texline @tmath{\sigma_{ij}^2} | 24451 @texline @math{\sigma_{ij}^2} |
24464 @infoline @expr{sigma_i_j^2} | 24452 @infoline @expr{sigma_i_j^2} |
24465 that describe the correlation between pairs of parameters. (A related | 24453 that describe the correlation between pairs of parameters. (A related |
24466 set of numbers, the @dfn{linear correlation coefficients} | 24454 set of numbers, the @dfn{linear correlation coefficients} |
24467 @texline @tmath{r_{ij}}, | 24455 @texline @math{r_{ij}}, |
24468 @infoline @expr{r_i_j}, | 24456 @infoline @expr{r_i_j}, |
24469 are defined as | 24457 are defined as |
24470 @texline @tmath{\sigma_{ij}^2 / \sigma_i \, \sigma_j}.) | 24458 @texline @math{\sigma_{ij}^2 / \sigma_i \, \sigma_j}.) |
24471 @infoline @expr{sigma_i_j^2 / sigma_i sigma_j}.) | 24459 @infoline @expr{sigma_i_j^2 / sigma_i sigma_j}.) |
24472 | 24460 |
24473 @item | 24461 @item |
24474 A vector of @expr{M} ``parameter filter'' functions whose | 24462 A vector of @expr{M} ``parameter filter'' functions whose |
24475 meanings are described below. If no filters are necessary this | 24463 meanings are described below. If no filters are necessary this |
24476 will instead be an empty vector; this is always the case for the | 24464 will instead be an empty vector; this is always the case for the |
24477 polynomial and multilinear fits described so far. | 24465 polynomial and multilinear fits described so far. |
24478 | 24466 |
24479 @item | 24467 @item |
24480 The value of | 24468 The value of |
24481 @texline @tmath{\chi^2} | 24469 @texline @math{\chi^2} |
24482 @infoline @expr{chi^2} | 24470 @infoline @expr{chi^2} |
24483 for the fit, calculated by the formulas shown above. This gives a | 24471 for the fit, calculated by the formulas shown above. This gives a |
24484 measure of the quality of the fit; statisticians consider | 24472 measure of the quality of the fit; statisticians consider |
24485 @texline @tmath{\chi^2 \approx N - M} | 24473 @texline @math{\chi^2 \approx N - M} |
24486 @infoline @expr{chi^2 = N - M} | 24474 @infoline @expr{chi^2 = N - M} |
24487 to indicate a moderately good fit (where again @expr{N} is the number of | 24475 to indicate a moderately good fit (where again @expr{N} is the number of |
24488 data points and @expr{M} is the number of parameters). | 24476 data points and @expr{M} is the number of parameters). |
24489 | 24477 |
24490 @item | 24478 @item |
24491 A measure of goodness of fit expressed as a probability @expr{Q}. | 24479 A measure of goodness of fit expressed as a probability @expr{Q}. |
24492 This is computed from the @code{utpc} probability distribution | 24480 This is computed from the @code{utpc} probability distribution |
24493 function using | 24481 function using |
24494 @texline @tmath{\chi^2} | 24482 @texline @math{\chi^2} |
24495 @infoline @expr{chi^2} | 24483 @infoline @expr{chi^2} |
24496 with @expr{N - M} degrees of freedom. A | 24484 with @expr{N - M} degrees of freedom. A |
24497 value of 0.5 implies a good fit; some texts recommend that often | 24485 value of 0.5 implies a good fit; some texts recommend that often |
24498 @expr{Q = 0.1} or even 0.001 can signify an acceptable fit. In | 24486 @expr{Q = 0.1} or even 0.001 can signify an acceptable fit. In |
24499 particular, | 24487 particular, |
24500 @texline @tmath{\chi^2} | 24488 @texline @math{\chi^2} |
24501 @infoline @expr{chi^2} | 24489 @infoline @expr{chi^2} |
24502 statistics assume the errors in your inputs | 24490 statistics assume the errors in your inputs |
24503 follow a normal (Gaussian) distribution; if they don't, you may | 24491 follow a normal (Gaussian) distribution; if they don't, you may |
24504 have to accept smaller values of @expr{Q}. | 24492 have to accept smaller values of @expr{Q}. |
24505 | 24493 |
24506 The @expr{Q} value is computed only if the input included error | 24494 The @expr{Q} value is computed only if the input included error |
24507 estimates. Otherwise, Calc will report the symbol @code{nan} | 24495 estimates. Otherwise, Calc will report the symbol @code{nan} |
24508 for @expr{Q}. The reason is that in this case the | 24496 for @expr{Q}. The reason is that in this case the |
24509 @texline @tmath{\chi^2} | 24497 @texline @math{\chi^2} |
24510 @infoline @expr{chi^2} | 24498 @infoline @expr{chi^2} |
24511 value has effectively been used to estimate the original errors | 24499 value has effectively been used to estimate the original errors |
24512 in the input, and thus there is no redundant information left | 24500 in the input, and thus there is no redundant information left |
24513 over to use for a confidence test. | 24501 over to use for a confidence test. |
24514 @end enumerate | 24502 @end enumerate |
24523 | 24511 |
24524 Here is a complete list of the standard models recognized by @kbd{a F}: | 24512 Here is a complete list of the standard models recognized by @kbd{a F}: |
24525 | 24513 |
24526 @table @kbd | 24514 @table @kbd |
24527 @item 1 | 24515 @item 1 |
24528 Linear or multilinear. @i{a + b x + c y + d z}. | 24516 Linear or multilinear. @mathit{a + b x + c y + d z}. |
24529 @item 2-9 | 24517 @item 2-9 |
24530 Polynomials. @i{a + b x + c x^2 + d x^3}. | 24518 Polynomials. @mathit{a + b x + c x^2 + d x^3}. |
24531 @item e | 24519 @item e |
24532 Exponential. @i{a} @t{exp}@i{(b x)} @t{exp}@i{(c y)}. | 24520 Exponential. @mathit{a} @t{exp}@mathit{(b x)} @t{exp}@mathit{(c y)}. |
24533 @item E | 24521 @item E |
24534 Base-10 exponential. @i{a} @t{10^}@i{(b x)} @t{10^}@i{(c y)}. | 24522 Base-10 exponential. @mathit{a} @t{10^}@mathit{(b x)} @t{10^}@mathit{(c y)}. |
24535 @item x | 24523 @item x |
24536 Exponential (alternate notation). @t{exp}@i{(a + b x + c y)}. | 24524 Exponential (alternate notation). @t{exp}@mathit{(a + b x + c y)}. |
24537 @item X | 24525 @item X |
24538 Base-10 exponential (alternate). @t{10^}@i{(a + b x + c y)}. | 24526 Base-10 exponential (alternate). @t{10^}@mathit{(a + b x + c y)}. |
24539 @item l | 24527 @item l |
24540 Logarithmic. @i{a + b} @t{ln}@i{(x) + c} @t{ln}@i{(y)}. | 24528 Logarithmic. @mathit{a + b} @t{ln}@mathit{(x) + c} @t{ln}@mathit{(y)}. |
24541 @item L | 24529 @item L |
24542 Base-10 logarithmic. @i{a + b} @t{log10}@i{(x) + c} @t{log10}@i{(y)}. | 24530 Base-10 logarithmic. @mathit{a + b} @t{log10}@mathit{(x) + c} @t{log10}@mathit{(y)}. |
24543 @item ^ | 24531 @item ^ |
24544 General exponential. @i{a b^x c^y}. | 24532 General exponential. @mathit{a b^x c^y}. |
24545 @item p | 24533 @item p |
24546 Power law. @i{a x^b y^c}. | 24534 Power law. @mathit{a x^b y^c}. |
24547 @item q | 24535 @item q |
24548 Quadratic. @i{a + b (x-c)^2 + d (x-e)^2}. | 24536 Quadratic. @mathit{a + b (x-c)^2 + d (x-e)^2}. |
24549 @item g | 24537 @item g |
24550 Gaussian. | 24538 Gaussian. |
24551 @texline @tmath{{a \over b \sqrt{2 \pi}} \exp\left( -{1 \over 2} \left( x - c \over b \right)^2 \right)}. | 24539 @texline @math{{a \over b \sqrt{2 \pi}} \exp\left( -{1 \over 2} \left( x - c \over b \right)^2 \right)}. |
24552 @infoline @i{(a / b sqrt(2 pi)) exp(-0.5*((x-c)/b)^2)}. | 24540 @infoline @mathit{(a / b sqrt(2 pi)) exp(-0.5*((x-c)/b)^2)}. |
24553 @end table | 24541 @end table |
24554 | 24542 |
24555 All of these models are used in the usual way; just press the appropriate | 24543 All of these models are used in the usual way; just press the appropriate |
24556 letter at the model prompt, and choose variable names if you wish. The | 24544 letter at the model prompt, and choose variable names if you wish. The |
24557 result will be a formula as shown in the above table, with the best-fit | 24545 result will be a formula as shown in the above table, with the best-fit |
24659 | 24647 |
24660 Calc uses the principal values of inverse functions like @code{ln} | 24648 Calc uses the principal values of inverse functions like @code{ln} |
24661 and @code{arcsin} when doing fits. For example, when you enter | 24649 and @code{arcsin} when doing fits. For example, when you enter |
24662 the model @samp{y = sin(a t + b)} Calc actually uses the easier | 24650 the model @samp{y = sin(a t + b)} Calc actually uses the easier |
24663 form @samp{arcsin(y) = a t + b}. The @code{arcsin} function always | 24651 form @samp{arcsin(y) = a t + b}. The @code{arcsin} function always |
24664 returns results in the range from @i{-90} to 90 degrees (or the | 24652 returns results in the range from @mathit{-90} to 90 degrees (or the |
24665 equivalent range in radians). Suppose you had data that you | 24653 equivalent range in radians). Suppose you had data that you |
24666 believed to represent roughly three oscillations of a sine wave, | 24654 believed to represent roughly three oscillations of a sine wave, |
24667 so that the argument of the sine might go from zero to | 24655 so that the argument of the sine might go from zero to |
24668 @texline @tmath{3\times360} | 24656 @texline @math{3\times360} |
24669 @infoline @i{3*360} | 24657 @infoline @mathit{3*360} |
24670 degrees. | 24658 degrees. |
24671 The above model would appear to be a good way to determine the | 24659 The above model would appear to be a good way to determine the |
24672 true frequency and phase of the sine wave, but in practice it | 24660 true frequency and phase of the sine wave, but in practice it |
24673 would fail utterly. The righthand side of the actual model | 24661 would fail utterly. The righthand side of the actual model |
24674 @samp{arcsin(y) = a t + b} will grow smoothly with @expr{t}, but | 24662 @samp{arcsin(y) = a t + b} will grow smoothly with @expr{t}, but |
24675 the lefthand side will bounce back and forth between @i{-90} and 90. | 24663 the lefthand side will bounce back and forth between @mathit{-90} and 90. |
24676 No values of @expr{a} and @expr{b} can make the two sides match, | 24664 No values of @expr{a} and @expr{b} can make the two sides match, |
24677 even approximately. | 24665 even approximately. |
24678 | 24666 |
24679 There is no good solution to this problem at present. You could | 24667 There is no good solution to this problem at present. You could |
24680 restrict your data to small enough ranges so that the above problem | 24668 restrict your data to small enough ranges so that the above problem |
24725 ln(y) = ln(a) + b ln(x) | 24713 ln(y) = ln(a) + b ln(x) |
24726 @end example | 24714 @end example |
24727 | 24715 |
24728 @noindent | 24716 @noindent |
24729 which matches the desired form with | 24717 which matches the desired form with |
24730 @texline @tmath{Y = \ln(y)}, | 24718 @texline @math{Y = \ln(y)}, |
24731 @infoline @expr{Y = ln(y)}, | 24719 @infoline @expr{Y = ln(y)}, |
24732 @texline @tmath{A = \ln(a)}, | 24720 @texline @math{A = \ln(a)}, |
24733 @infoline @expr{A = ln(a)}, | 24721 @infoline @expr{A = ln(a)}, |
24734 @expr{F = 1}, @expr{B = b}, and | 24722 @expr{F = 1}, @expr{B = b}, and |
24735 @texline @tmath{G = \ln(x)}. | 24723 @texline @math{G = \ln(x)}. |
24736 @infoline @expr{G = ln(x)}. | 24724 @infoline @expr{G = ln(x)}. |
24737 Calc thus computes the logarithms of your @expr{y} and @expr{x} values, | 24725 Calc thus computes the logarithms of your @expr{y} and @expr{x} values, |
24738 does a linear fit for @expr{A} and @expr{B}, then solves to get | 24726 does a linear fit for @expr{A} and @expr{B}, then solves to get |
24739 @texline @tmath{a = \exp(A)} | 24727 @texline @math{a = \exp(A)} |
24740 @infoline @expr{a = exp(A)} | 24728 @infoline @expr{a = exp(A)} |
24741 and @expr{b = B}. | 24729 and @expr{b = B}. |
24742 | 24730 |
24743 Another interesting example is the ``quadratic'' model, which can | 24731 Another interesting example is the ``quadratic'' model, which can |
24744 be handled by expanding according to the distributive law. | 24732 be handled by expanding according to the distributive law. |
24748 y = a + b c^2 - 2 b c x + b x^2 | 24736 y = a + b c^2 - 2 b c x + b x^2 |
24749 @end example | 24737 @end example |
24750 | 24738 |
24751 @noindent | 24739 @noindent |
24752 which matches with @expr{Y = y}, @expr{A = a + b c^2}, @expr{F = 1}, | 24740 which matches with @expr{Y = y}, @expr{A = a + b c^2}, @expr{F = 1}, |
24753 @expr{B = -2 b c}, @expr{G = x} (the @i{-2} factor could just as easily | 24741 @expr{B = -2 b c}, @expr{G = x} (the @mathit{-2} factor could just as easily |
24754 have been put into @expr{G} instead of @expr{B}), @expr{C = b}, and | 24742 have been put into @expr{G} instead of @expr{B}), @expr{C = b}, and |
24755 @expr{H = x^2}. | 24743 @expr{H = x^2}. |
24756 | 24744 |
24757 The Gaussian model looks quite complicated, but a closer examination | 24745 The Gaussian model looks quite complicated, but a closer examination |
24758 shows that it's actually similar to the quadratic model but with an | 24746 shows that it's actually similar to the quadratic model but with an |
24780 @end tex | 24768 @end tex |
24781 | 24769 |
24782 A last desperate step would be to use the general-purpose | 24770 A last desperate step would be to use the general-purpose |
24783 @code{minimize} function rather than @code{fit}. After all, both | 24771 @code{minimize} function rather than @code{fit}. After all, both |
24784 functions solve the problem of minimizing an expression (the | 24772 functions solve the problem of minimizing an expression (the |
24785 @texline @tmath{\chi^2} | 24773 @texline @math{\chi^2} |
24786 @infoline @expr{chi^2} | 24774 @infoline @expr{chi^2} |
24787 sum) by adjusting certain parameters in the expression. The @kbd{a F} | 24775 sum) by adjusting certain parameters in the expression. The @kbd{a F} |
24788 command is able to use a vastly more efficient algorithm due to its | 24776 command is able to use a vastly more efficient algorithm due to its |
24789 special knowledge about linear chi-square sums, but the @kbd{a N} | 24777 special knowledge about linear chi-square sums, but the @kbd{a N} |
24790 command can do the same thing by brute force. | 24778 command can do the same thing by brute force. |
24791 | 24779 |
24792 A compromise would be to pick out a few parameters without which the | 24780 A compromise would be to pick out a few parameters without which the |
24793 fit is linearizable, and use @code{minimize} on a call to @code{fit} | 24781 fit is linearizable, and use @code{minimize} on a call to @code{fit} |
24794 which efficiently takes care of the rest of the parameters. The thing | 24782 which efficiently takes care of the rest of the parameters. The thing |
24795 to be minimized would be the value of | 24783 to be minimized would be the value of |
24796 @texline @tmath{\chi^2} | 24784 @texline @math{\chi^2} |
24797 @infoline @expr{chi^2} | 24785 @infoline @expr{chi^2} |
24798 returned as the fifth result of the @code{xfit} function: | 24786 returned as the fifth result of the @code{xfit} function: |
24799 | 24787 |
24800 @smallexample | 24788 @smallexample |
24801 minimize(xfit(gaus(a,b,c,d,x), x, [a,b,c], data)_5, d, guess) | 24789 minimize(xfit(gaus(a,b,c,d,x), x, [a,b,c], data)_5, d, guess) |
24851 of the sum of the squares of the errors. It then changes @expr{x} | 24839 of the sum of the squares of the errors. It then changes @expr{x} |
24852 and @expr{y} to be plain numbers, and makes @expr{z} into an error | 24840 and @expr{y} to be plain numbers, and makes @expr{z} into an error |
24853 form with this combined error. The @expr{Y(x,y,z)} part of the | 24841 form with this combined error. The @expr{Y(x,y,z)} part of the |
24854 linearized model is evaluated, and the result should be an error | 24842 linearized model is evaluated, and the result should be an error |
24855 form. The error part of that result is used for | 24843 form. The error part of that result is used for |
24856 @texline @tmath{\sigma_i} | 24844 @texline @math{\sigma_i} |
24857 @infoline @expr{sigma_i} | 24845 @infoline @expr{sigma_i} |
24858 for the data point. If for some reason @expr{Y(x,y,z)} does not return | 24846 for the data point. If for some reason @expr{Y(x,y,z)} does not return |
24859 an error form, the combined error from @expr{z} is used directly for | 24847 an error form, the combined error from @expr{z} is used directly for |
24860 @texline @tmath{\sigma_i}. | 24848 @texline @math{\sigma_i}. |
24861 @infoline @expr{sigma_i}. | 24849 @infoline @expr{sigma_i}. |
24862 Finally, @expr{z} is also stripped of its error | 24850 Finally, @expr{z} is also stripped of its error |
24863 for use in computing @expr{F(x,y,z)}, @expr{G(x,y,z)} and so on; | 24851 for use in computing @expr{F(x,y,z)}, @expr{G(x,y,z)} and so on; |
24864 the righthand side of the linearized model is computed in regular | 24852 the righthand side of the linearized model is computed in regular |
24865 arithmetic with no error forms. | 24853 arithmetic with no error forms. |
24867 (While these rules may seem complicated, they are designed to do | 24855 (While these rules may seem complicated, they are designed to do |
24868 the most reasonable thing in the typical case that @expr{Y(x,y,z)} | 24856 the most reasonable thing in the typical case that @expr{Y(x,y,z)} |
24869 depends only on the dependent variable @expr{z}, and in fact is | 24857 depends only on the dependent variable @expr{z}, and in fact is |
24870 often simply equal to @expr{z}. For common cases like polynomials | 24858 often simply equal to @expr{z}. For common cases like polynomials |
24871 and multilinear models, the combined error is simply used as the | 24859 and multilinear models, the combined error is simply used as the |
24872 @texline @tmath{\sigma} | 24860 @texline @math{\sigma} |
24873 @infoline @expr{sigma} | 24861 @infoline @expr{sigma} |
24874 for the data point with no further ado.) | 24862 for the data point with no further ado.) |
24875 | 24863 |
24876 @tex | 24864 @tex |
24877 \bigskip | 24865 \bigskip |
25221 | 25209 |
25222 If the lower limit is greater than the upper limit (assuming a | 25210 If the lower limit is greater than the upper limit (assuming a |
25223 positive step size), the result is generally zero. However, | 25211 positive step size), the result is generally zero. However, |
25224 Calc only guarantees a zero result when the upper limit is | 25212 Calc only guarantees a zero result when the upper limit is |
25225 exactly one step less than the lower limit, i.e., if the number | 25213 exactly one step less than the lower limit, i.e., if the number |
25226 of iterations is @i{-1}. Thus @samp{sum(f(k), k, n, n-1)} is zero | 25214 of iterations is @mathit{-1}. Thus @samp{sum(f(k), k, n, n-1)} is zero |
25227 but the sum from @samp{n} to @samp{n-2} may report a nonzero value | 25215 but the sum from @samp{n} to @samp{n-2} may report a nonzero value |
25228 if Calc used a closed form solution. | 25216 if Calc used a closed form solution. |
25229 | 25217 |
25230 Calc's logical predicates like @expr{a < b} return 1 for ``true'' | 25218 Calc's logical predicates like @expr{a < b} return 1 for ``true'' |
25231 and 0 for ``false.'' @xref{Logical Operations}. This can be | 25219 and 0 for ``false.'' @xref{Logical Operations}. This can be |
25247 this would be a division by zero. But at @expr{k = k_0}, this | 25235 this would be a division by zero. But at @expr{k = k_0}, this |
25248 formula works out to the indeterminate form @expr{0 / 0}, which | 25236 formula works out to the indeterminate form @expr{0 / 0}, which |
25249 Calc will not assume is zero. Better would be to use | 25237 Calc will not assume is zero. Better would be to use |
25250 @samp{(k != k_0) ? 1/(k-k_0) : 0}; the @samp{? :} operator does | 25238 @samp{(k != k_0) ? 1/(k-k_0) : 0}; the @samp{? :} operator does |
25251 an ``if-then-else'' test: This expression says, ``if | 25239 an ``if-then-else'' test: This expression says, ``if |
25252 @texline @tmath{k \ne k_0}, | 25240 @texline @math{k \ne k_0}, |
25253 @infoline @expr{k != k_0}, | 25241 @infoline @expr{k != k_0}, |
25254 then @expr{1/(k-k_0)}, else zero.'' Now the formula @expr{1/(k-k_0)} | 25242 then @expr{1/(k-k_0)}, else zero.'' Now the formula @expr{1/(k-k_0)} |
25255 will not even be evaluated by Calc when @expr{k = k_0}. | 25243 will not even be evaluated by Calc when @expr{k = k_0}. |
25256 | 25244 |
25257 @cindex Alternating sums | 25245 @cindex Alternating sums |
26262 f(a b) := a f(b) :: real(a)]} is stored in variable @samp{linearF}, | 26250 f(a b) := a f(b) :: real(a)]} is stored in variable @samp{linearF}, |
26263 then the rule set @samp{[f(0) := 0, import(linearF)]} will apply | 26251 then the rule set @samp{[f(0) := 0, import(linearF)]} will apply |
26264 all three rules. It is possible to modify the imported rules | 26252 all three rules. It is possible to modify the imported rules |
26265 slightly: @samp{import(x, v1, x1, v2, x2, @dots{})} imports | 26253 slightly: @samp{import(x, v1, x1, v2, x2, @dots{})} imports |
26266 the rule set @expr{x} with all occurrences of | 26254 the rule set @expr{x} with all occurrences of |
26267 @texline @tmath{v_1}, | 26255 @texline @math{v_1}, |
26268 @infoline @expr{v1}, | 26256 @infoline @expr{v1}, |
26269 as either a variable name or a function name, replaced with | 26257 as either a variable name or a function name, replaced with |
26270 @texline @tmath{x_1} | 26258 @texline @math{x_1} |
26271 @infoline @expr{x1} | 26259 @infoline @expr{x1} |
26272 and so on. (If | 26260 and so on. (If |
26273 @texline @tmath{v_1} | 26261 @texline @math{v_1} |
26274 @infoline @expr{v1} | 26262 @infoline @expr{v1} |
26275 is used as a function name, then | 26263 is used as a function name, then |
26276 @texline @tmath{x_1} | 26264 @texline @math{x_1} |
26277 @infoline @expr{x1} | 26265 @infoline @expr{x1} |
26278 must be either a function name itself or a @w{@samp{< >}} nameless | 26266 must be either a function name itself or a @w{@samp{< >}} nameless |
26279 function; @pxref{Specifying Operators}.) For example, @samp{[g(0) := 0, | 26267 function; @pxref{Specifying Operators}.) For example, @samp{[g(0) := 0, |
26280 import(linearF, f, g)]} applies the linearity rules to the function | 26268 import(linearF, f, g)]} applies the linearity rules to the function |
26281 @samp{g} instead of @samp{f}. Imports can be nested, but the | 26269 @samp{g} instead of @samp{f}. Imports can be nested, but the |
27737 the @kbd{u g} command gets the definition of one of these constants | 27725 the @kbd{u g} command gets the definition of one of these constants |
27738 in its normal terms, and @kbd{u b} expresses the definition in base | 27726 in its normal terms, and @kbd{u b} expresses the definition in base |
27739 units. | 27727 units. |
27740 | 27728 |
27741 Two units, @code{pi} and @code{fsc} (the fine structure constant, | 27729 Two units, @code{pi} and @code{fsc} (the fine structure constant, |
27742 approximately @i{1/137}) are dimensionless. The units simplification | 27730 approximately @mathit{1/137}) are dimensionless. The units simplification |
27743 commands simply treat these names as equivalent to their corresponding | 27731 commands simply treat these names as equivalent to their corresponding |
27744 values. However you can, for example, use @kbd{u c} to convert a pure | 27732 values. However you can, for example, use @kbd{u c} to convert a pure |
27745 number into multiples of the fine structure constant, or @kbd{u b} to | 27733 number into multiples of the fine structure constant, or @kbd{u b} to |
27746 convert this back into a pure number. (When @kbd{u c} prompts for the | 27734 convert this back into a pure number. (When @kbd{u c} prompts for the |
27747 ``old units,'' just enter a blank line to signify that the value | 27735 ``old units,'' just enter a blank line to signify that the value |
27954 | 27942 |
27955 All the arithmetic stores accept the Inverse prefix to reverse the | 27943 All the arithmetic stores accept the Inverse prefix to reverse the |
27956 order of the operands. If @expr{v} represents the contents of the | 27944 order of the operands. If @expr{v} represents the contents of the |
27957 variable, and @expr{a} is the value drawn from the stack, then regular | 27945 variable, and @expr{a} is the value drawn from the stack, then regular |
27958 @w{@kbd{s -}} assigns | 27946 @w{@kbd{s -}} assigns |
27959 @texline @tmath{v \coloneq v - a}, | 27947 @texline @math{v \coloneq v - a}, |
27960 @infoline @expr{v := v - a}, | 27948 @infoline @expr{v := v - a}, |
27961 but @kbd{I s -} assigns | 27949 but @kbd{I s -} assigns |
27962 @texline @tmath{v \coloneq a - v}. | 27950 @texline @math{v \coloneq a - v}. |
27963 @infoline @expr{v := a - v}. | 27951 @infoline @expr{v := a - v}. |
27964 While @kbd{I s *} might seem pointless, it is | 27952 While @kbd{I s *} might seem pointless, it is |
27965 useful if matrix multiplication is involved. Actually, all the | 27953 useful if matrix multiplication is involved. Actually, all the |
27966 arithmetic stores use formulas designed to behave usefully both | 27954 arithmetic stores use formulas designed to behave usefully both |
27967 forwards and backwards: | 27955 forwards and backwards: |
28544 In the first case, ``x'' and ``y'' are each vectors (not necessarily of | 28532 In the first case, ``x'' and ``y'' are each vectors (not necessarily of |
28545 the same length); either or both may instead be interval forms. The | 28533 the same length); either or both may instead be interval forms. The |
28546 ``z'' value must be a matrix with the same number of rows as elements | 28534 ``z'' value must be a matrix with the same number of rows as elements |
28547 in ``x'', and the same number of columns as elements in ``y''. The | 28535 in ``x'', and the same number of columns as elements in ``y''. The |
28548 result is a surface plot where | 28536 result is a surface plot where |
28549 @texline @tmath{z_{ij}} | 28537 @texline @math{z_{ij}} |
28550 @infoline @expr{z_ij} | 28538 @infoline @expr{z_ij} |
28551 is the height of the point | 28539 is the height of the point |
28552 at coordinate @expr{(x_i, y_j)} on the surface. The 3D graph will | 28540 at coordinate @expr{(x_i, y_j)} on the surface. The 3D graph will |
28553 be displayed from a certain default viewpoint; you can change this | 28541 be displayed from a certain default viewpoint; you can change this |
28554 viewpoint by adding a @samp{set view} to the @samp{*Gnuplot Commands*} | 28542 viewpoint by adding a @samp{set view} to the @samp{*Gnuplot Commands*} |
28655 that don't have common ``x'' values. (Of course, the range of ``x'' | 28643 that don't have common ``x'' values. (Of course, the range of ``x'' |
28656 values covered by all the curves ought to be roughly the same if | 28644 values covered by all the curves ought to be roughly the same if |
28657 they are to look nice on the same graph.) | 28645 they are to look nice on the same graph.) |
28658 | 28646 |
28659 For example, to plot | 28647 For example, to plot |
28660 @texline @tmath{\sin n x} | 28648 @texline @math{\sin n x} |
28661 @infoline @expr{sin(n x)} | 28649 @infoline @expr{sin(n x)} |
28662 for integers @expr{n} | 28650 for integers @expr{n} |
28663 from 1 to 5, you could use @kbd{v x} to create a vector of integers | 28651 from 1 to 5, you could use @kbd{v x} to create a vector of integers |
28664 (@expr{n}), then @kbd{V M '} or @kbd{V M $} to map @samp{sin(n x)} | 28652 (@expr{n}), then @kbd{V M '} or @kbd{V M $} to map @samp{sin(n x)} |
28665 across this vector. The resulting vector of formulas is suitable | 28653 across this vector. The resulting vector of formulas is suitable |
28906 @code{PointStyles} variables. These variables initially have no stored | 28894 @code{PointStyles} variables. These variables initially have no stored |
28907 values, but if you store a vector of integers in one of these variables, | 28895 values, but if you store a vector of integers in one of these variables, |
28908 the @kbd{g a} and @kbd{g f} commands will use those style numbers | 28896 the @kbd{g a} and @kbd{g f} commands will use those style numbers |
28909 instead of the defaults for new curves that are added to the graph. | 28897 instead of the defaults for new curves that are added to the graph. |
28910 An entry should be a positive integer for a specific style, or 0 to let | 28898 An entry should be a positive integer for a specific style, or 0 to let |
28911 the style be chosen automatically, or @i{-1} to turn off lines or points | 28899 the style be chosen automatically, or @mathit{-1} to turn off lines or points |
28912 altogether. If there are more curves than elements in the vector, the | 28900 altogether. If there are more curves than elements in the vector, the |
28913 last few curves will continue to have the default styles. Of course, | 28901 last few curves will continue to have the default styles. Of course, |
28914 you can later use @kbd{g s} and @kbd{g S} to change any of these styles. | 28902 you can later use @kbd{g s} and @kbd{g S} to change any of these styles. |
28915 | 28903 |
28916 For example, @kbd{'[2 -1 3] @key{RET} s t LineStyles} causes the first curve | 28904 For example, @kbd{'[2 -1 3] @key{RET} s t LineStyles} causes the first curve |
28945 terminals with no special graphics facilities. It writes a crude | 28933 terminals with no special graphics facilities. It writes a crude |
28946 picture of the graph composed of characters like @code{-} and @code{|} | 28934 picture of the graph composed of characters like @code{-} and @code{|} |
28947 to a buffer called @samp{*Gnuplot Trail*}, which Calc then displays. | 28935 to a buffer called @samp{*Gnuplot Trail*}, which Calc then displays. |
28948 The graph is made the same size as the Emacs screen, which on most | 28936 The graph is made the same size as the Emacs screen, which on most |
28949 dumb terminals will be | 28937 dumb terminals will be |
28950 @texline @tmath{80\times24} | 28938 @texline @math{80\times24} |
28951 @infoline 80x24 | 28939 @infoline 80x24 |
28952 characters. The graph is displayed in | 28940 characters. The graph is displayed in |
28953 an Emacs ``recursive edit''; type @kbd{q} or @kbd{M-# M-#} to exit | 28941 an Emacs ``recursive edit''; type @kbd{q} or @kbd{M-# M-#} to exit |
28954 the recursive edit and return to Calc. Note that the @code{dumb} | 28942 the recursive edit and return to Calc. Note that the @code{dumb} |
28955 device is present only in GNUPLOT 3.0 and later versions. | 28943 device is present only in GNUPLOT 3.0 and later versions. |
29255 @w{@samp{2 +/- 3 4 +/- 5}}, then grabbing with a prefix argument of 8 | 29243 @w{@samp{2 +/- 3 4 +/- 5}}, then grabbing with a prefix argument of 8 |
29256 would correctly split the line into two error forms. | 29244 would correctly split the line into two error forms. |
29257 | 29245 |
29258 @xref{Matrix Functions}, to see how to pull the matrix apart into its | 29246 @xref{Matrix Functions}, to see how to pull the matrix apart into its |
29259 constituent rows and columns. (If it is a | 29247 constituent rows and columns. (If it is a |
29260 @texline @tmath{1\times1} | 29248 @texline @math{1\times1} |
29261 @infoline 1x1 | 29249 @infoline 1x1 |
29262 matrix, just hit @kbd{v u} (@code{calc-unpack}) twice.) | 29250 matrix, just hit @kbd{v u} (@code{calc-unpack}) twice.) |
29263 | 29251 |
29264 @kindex M-# : | 29252 @kindex M-# : |
29265 @kindex M-# _ | 29253 @kindex M-# _ |
29593 same limit as last time. | 29581 same limit as last time. |
29594 | 29582 |
29595 @key{INV GCD} computes the LCM (least common multiple) function. | 29583 @key{INV GCD} computes the LCM (least common multiple) function. |
29596 | 29584 |
29597 @key{INV FACT} is the gamma function. | 29585 @key{INV FACT} is the gamma function. |
29598 @texline @tmath{\Gamma(x) = (x-1)!}. | 29586 @texline @math{\Gamma(x) = (x-1)!}. |
29599 @infoline @expr{gamma(x) = (x-1)!}. | 29587 @infoline @expr{gamma(x) = (x-1)!}. |
29600 | 29588 |
29601 @key{PERM} is the number-of-permutations function, which is on the | 29589 @key{PERM} is the number-of-permutations function, which is on the |
29602 @kbd{H k c} key in normal Calc. | 29590 @kbd{H k c} key in normal Calc. |
29603 | 29591 |
31021 If you give a numeric prefix argument of 1 to @kbd{Z (}, the loop is | 31009 If you give a numeric prefix argument of 1 to @kbd{Z (}, the loop is |
31022 forced to use upward-counting conventions. In this case, if @var{initial} | 31010 forced to use upward-counting conventions. In this case, if @var{initial} |
31023 is greater than @var{final} the body will not be executed at all. | 31011 is greater than @var{final} the body will not be executed at all. |
31024 Note that @var{step} may still be negative in this loop; the prefix | 31012 Note that @var{step} may still be negative in this loop; the prefix |
31025 argument merely constrains the loop-finished test. Likewise, a prefix | 31013 argument merely constrains the loop-finished test. Likewise, a prefix |
31026 argument of @i{-1} forces downward-counting conventions. | 31014 argument of @mathit{-1} forces downward-counting conventions. |
31027 | 31015 |
31028 @kindex Z @{ | 31016 @kindex Z @{ |
31029 @kindex Z @} | 31017 @kindex Z @} |
31030 @pindex calc-kbd-loop | 31018 @pindex calc-kbd-loop |
31031 @pindex calc-kbd-end-loop | 31019 @pindex calc-kbd-end-loop |
31992 @starindex | 31980 @starindex |
31993 @end ignore | 31981 @end ignore |
31994 @tindex mysin | 31982 @tindex mysin |
31995 A somewhat limited sine function could be defined as follows, using the | 31983 A somewhat limited sine function could be defined as follows, using the |
31996 well-known Taylor series expansion for | 31984 well-known Taylor series expansion for |
31997 @texline @tmath{\sin x}: | 31985 @texline @math{\sin x}: |
31998 @infoline @samp{sin(x)}: | 31986 @infoline @samp{sin(x)}: |
31999 | 31987 |
32000 @smallexample | 31988 @smallexample |
32001 (defmath mysin ((float (anglep x))) | 31989 (defmath mysin ((float (anglep x))) |
32002 (interactive 1 "mysn") | 31990 (interactive 1 "mysn") |
32515 which is not a Lisp list. | 32503 which is not a Lisp list. |
32516 | 32504 |
32517 Large integers are stored as lists of the form @samp{(bigpos @var{d0} | 32505 Large integers are stored as lists of the form @samp{(bigpos @var{d0} |
32518 @var{d1} @var{d2} @dots{})} for positive integers 1000000 or more, or | 32506 @var{d1} @var{d2} @dots{})} for positive integers 1000000 or more, or |
32519 @samp{(bigneg @var{d0} @var{d1} @var{d2} @dots{})} for negative integers | 32507 @samp{(bigneg @var{d0} @var{d1} @var{d2} @dots{})} for negative integers |
32520 @i{-1000000} or less. Each @var{d} is a base-1000 ``digit,'' a Lisp integer | 32508 @mathit{-1000000} or less. Each @var{d} is a base-1000 ``digit,'' a Lisp integer |
32521 from 0 to 999. The least significant digit is @var{d0}; the last digit, | 32509 from 0 to 999. The least significant digit is @var{d0}; the last digit, |
32522 @var{dn}, which is always nonzero, is the most significant digit. For | 32510 @var{dn}, which is always nonzero, is the most significant digit. For |
32523 example, the integer @i{-12345678} is stored as @samp{(bigneg 678 345 12)}. | 32511 example, the integer @mathit{-12345678} is stored as @samp{(bigneg 678 345 12)}. |
32524 | 32512 |
32525 The distinction between small and large integers is entirely hidden from | 32513 The distinction between small and large integers is entirely hidden from |
32526 the user. In @code{defmath} definitions, the Lisp predicate @code{integerp} | 32514 the user. In @code{defmath} definitions, the Lisp predicate @code{integerp} |
32527 returns true for either kind of integer, and in general both big and small | 32515 returns true for either kind of integer, and in general both big and small |
32528 integers are accepted anywhere the word ``integer'' is used in this manual. | 32516 integers are accepted anywhere the word ``integer'' is used in this manual. |
32539 Floating-point numbers are stored in the form, @samp{(float @var{mant} | 32527 Floating-point numbers are stored in the form, @samp{(float @var{mant} |
32540 @var{exp})}, where @var{mant} (the ``mantissa'') is an integer less than | 32528 @var{exp})}, where @var{mant} (the ``mantissa'') is an integer less than |
32541 @samp{10^@var{p}} in absolute value (@var{p} represents the current | 32529 @samp{10^@var{p}} in absolute value (@var{p} represents the current |
32542 precision), and @var{exp} (the ``exponent'') is a fixnum. The value of | 32530 precision), and @var{exp} (the ``exponent'') is a fixnum. The value of |
32543 the float is @samp{@var{mant} * 10^@var{exp}}. For example, the number | 32531 the float is @samp{@var{mant} * 10^@var{exp}}. For example, the number |
32544 @i{-3.14} is stored as @samp{(float -314 -2) = -314*10^-2}. Other constraints | 32532 @mathit{-3.14} is stored as @samp{(float -314 -2) = -314*10^-2}. Other constraints |
32545 are that the number 0.0 is always stored as @samp{(float 0 0)}, and, | 32533 are that the number 0.0 is always stored as @samp{(float 0 0)}, and, |
32546 except for the 0.0 case, the rightmost base-10 digit of @var{mant} is | 32534 except for the 0.0 case, the rightmost base-10 digit of @var{mant} is |
32547 always nonzero. (If the rightmost digit is zero, the number is | 32535 always nonzero. (If the rightmost digit is zero, the number is |
32548 rearranged by dividing @var{mant} by ten and incrementing @var{exp}.) | 32536 rearranged by dividing @var{mant} by ten and incrementing @var{exp}.) |
32549 | 32537 |
32851 is displayed. If the prefix is one, the unary function @var{unary} | 32839 is displayed. If the prefix is one, the unary function @var{unary} |
32852 is applied to the top stack element, or, if @var{unary} is not | 32840 is applied to the top stack element, or, if @var{unary} is not |
32853 specified, nothing happens. When the argument is two or more, | 32841 specified, nothing happens. When the argument is two or more, |
32854 the binary function @var{func} is reduced across the top @var{arg} | 32842 the binary function @var{func} is reduced across the top @var{arg} |
32855 stack elements; when the argument is negative, the function is | 32843 stack elements; when the argument is negative, the function is |
32856 mapped between the next-to-top @i{-@var{arg}} stack elements and the | 32844 mapped between the next-to-top @mathit{-@var{arg}} stack elements and the |
32857 top element. | 32845 top element. |
32858 @end defun | 32846 @end defun |
32859 | 32847 |
32860 @defun calc-stack-size | 32848 @defun calc-stack-size |
32861 Return the number of elements on the stack as an integer. This count | 32849 Return the number of elements on the stack as an integer. This count |
33270 modulo forms are recursively floated. If the argument is a variable | 33258 modulo forms are recursively floated. If the argument is a variable |
33271 or formula, this calls @code{reject-arg}. | 33259 or formula, this calls @code{reject-arg}. |
33272 @end defun | 33260 @end defun |
33273 | 33261 |
33274 @defun compare x y | 33262 @defun compare x y |
33275 Compare the numbers @var{x} and @var{y}, and return @i{-1} if | 33263 Compare the numbers @var{x} and @var{y}, and return @mathit{-1} if |
33276 @samp{(lessp @var{x} @var{y})}, 1 if @samp{(lessp @var{y} @var{x})}, | 33264 @samp{(lessp @var{x} @var{y})}, 1 if @samp{(lessp @var{y} @var{x})}, |
33277 0 if @samp{(math-equal @var{x} @var{y})}, or 2 if the order is | 33265 0 if @samp{(math-equal @var{x} @var{y})}, or 2 if the order is |
33278 undefined or cannot be determined. | 33266 undefined or cannot be determined. |
33279 @end defun | 33267 @end defun |
33280 | 33268 |
33283 @samp{ceil(log10(@var{n}))}, but much more efficient. Zero is | 33271 @samp{ceil(log10(@var{n}))}, but much more efficient. Zero is |
33284 considered to have zero digits. | 33272 considered to have zero digits. |
33285 @end defun | 33273 @end defun |
33286 | 33274 |
33287 @defun scale-int x n | 33275 @defun scale-int x n |
33288 Shift integer @var{x} left @var{n} decimal digits, or right @i{-@var{n}} | 33276 Shift integer @var{x} left @var{n} decimal digits, or right @mathit{-@var{n}} |
33289 digits with truncation toward zero. | 33277 digits with truncation toward zero. |
33290 @end defun | 33278 @end defun |
33291 | 33279 |
33292 @defun scale-rounding x n | 33280 @defun scale-rounding x n |
33293 Like @code{scale-int}, except that a right shift rounds to the nearest | 33281 Like @code{scale-int}, except that a right shift rounds to the nearest |
33491 @end defun | 33479 @end defun |
33492 | 33480 |
33493 @defun quarter-integer n | 33481 @defun quarter-integer n |
33494 If @var{n} is an integer or integer-valued float, this function | 33482 If @var{n} is an integer or integer-valued float, this function |
33495 returns zero. If @var{n} is a half-integer (i.e., an integer plus | 33483 returns zero. If @var{n} is a half-integer (i.e., an integer plus |
33496 @i{1:2} or 0.5), it returns 2. If @var{n} is a quarter-integer, | 33484 @mathit{1:2} or 0.5), it returns 2. If @var{n} is a quarter-integer, |
33497 it returns 1 or 3. If @var{n} is anything else, this function | 33485 it returns 1 or 3. If @var{n} is anything else, this function |
33498 returns @code{nil}. | 33486 returns @code{nil}. |
33499 @end defun | 33487 @end defun |
33500 | 33488 |
33501 @node Vector Lisp Functions, Symbolic Lisp Functions, Computational Lisp Functions, Internals | 33489 @node Vector Lisp Functions, Symbolic Lisp Functions, Computational Lisp Functions, Internals |
35634 input data set. Each entry may be a single value or a vector of values. | 35622 input data set. Each entry may be a single value or a vector of values. |
35635 | 35623 |
35636 @c 20 | 35624 @c 20 |
35637 @item | 35625 @item |
35638 With a prefix argument of 1, take a single | 35626 With a prefix argument of 1, take a single |
35639 @texline @tmath{@var{n}\times2} | 35627 @texline @var{n}@math{\times2} |
35640 @infoline @i{@var{N}x2} | 35628 @infoline @mathit{@var{N}x2} |
35641 matrix from the stack instead of two separate data vectors. | 35629 matrix from the stack instead of two separate data vectors. |
35642 | 35630 |
35643 @c 21 | 35631 @c 21 |
35644 @item | 35632 @item |
35645 The row or column number @expr{n} may be given as a numeric prefix | 35633 The row or column number @expr{n} may be given as a numeric prefix |
35837 @c 47 | 35825 @c 47 |
35838 @item | 35826 @item |
35839 The variable is replaced by the formula shown on the right. The | 35827 The variable is replaced by the formula shown on the right. The |
35840 Inverse flag reverses the order of the operands, e.g., @kbd{I s - x} | 35828 Inverse flag reverses the order of the operands, e.g., @kbd{I s - x} |
35841 assigns | 35829 assigns |
35842 @texline @tmath{x \coloneq a-x}. | 35830 @texline @math{x \coloneq a-x}. |
35843 @infoline @expr{x := a-x}. | 35831 @infoline @expr{x := a-x}. |
35844 | 35832 |
35845 @c 48 | 35833 @c 48 |
35846 @item | 35834 @item |
35847 Press @kbd{?} repeatedly to see how to choose a model. Answer the | 35835 Press @kbd{?} repeatedly to see how to choose a model. Answer the |
35848 variables prompt with @expr{iv} or @expr{iv;pv} to specify | 35836 variables prompt with @expr{iv} or @expr{iv;pv} to specify |
35849 independent and parameter variables. A positive prefix argument | 35837 independent and parameter variables. A positive prefix argument |
35850 takes @i{@var{n}+1} vectors from the stack; a zero prefix takes a matrix | 35838 takes @mathit{@var{n}+1} vectors from the stack; a zero prefix takes a matrix |
35851 and a vector from the stack. | 35839 and a vector from the stack. |
35852 | 35840 |
35853 @c 49 | 35841 @c 49 |
35854 @item | 35842 @item |
35855 With a plain @kbd{C-u} prefix, replace the current region of the | 35843 With a plain @kbd{C-u} prefix, replace the current region of the |