| Title: | Mathematics at DEC |
| Moderator: | RUSURE::EDP |
| Created: | Mon Feb 03 1986 |
| Last Modified: | Fri Jun 06 1997 |
| Last Successful Update: | Fri Jun 06 1997 |
| Number of topics: | 2083 |
| Total number of notes: | 14613 |
A 2020 (�) spreadsheet user wants to calculate the factorial of a
variable cell; however he doesn't want to consume much of the
spreadsheet to do it. 2020 doesn't have an intrinsic factorial function
with which he could just say something like FACT(A2) where "A2" is the
address of a cell in the spreadsheet.
2020 *does* have a number of functions that use factorials: ACOS, ASIN,
ATAN, ATAN2, COS, EXP, LN, LOG, SIN, TAN. Also, 2020 has the standard
arithmetic functions + - * / ^.
Is there some way the user can use any of the above functions to
calculate a factorial?
/Dwayne
| T.R | Title | User | Personal Name | Date | Lines |
|---|---|---|---|---|---|
| 1252.1 | HPSTEK::XIA | In my beginning is my end. | Tue Jun 12 1990 13:07 | 4 | |
If your A2 is very large, you could use the Sterling (sp?) formula.
Otherwise, you will just have to use * .
Eugene
| |||||
| 1252.2 | GUESS::DERAMO | Colorado Rocky Mountain high | Tue Jun 12 1990 13:18 | 4 | |
What is available in the way of if-then-else, recursion, and iteration? Dan | |||||
| 1252.3 | More RE 2020 | DEC25::ROBERTS | Reason, Purpose, Self-esteem | Tue Jun 12 1990 17:51 | 50 |
2020 doesn't care too much for recursion; it thinks there are circular
references.
Iteration can be achieved in a couple of ways.
The first is through "goal seeking," a process of automatically
modifying one cell, recalculating all other cells, to reach a target.
For example, if the cells were initialized as:
A1: 1.00
A2: (A1)^3-5*(A1)^2+8*(A1)-12
it would continue to modify A1 until it was 3.71618865899311 and the
value of A2 was 0.0000000000. I don't know what algorithm it uses to
determine how to adjust A1 each time.
Iteration can also be performed by use of macros, too. The following
macro calculates a factorial. The topmost row and leftmost column are
not part of the macro; they're column and row identifiers. The macro is
executed by telling the spreadsheet to execute D0. The first macro
command, "#QUIET," just tells it not to display intermediate
calculations.
A B C D
0 6 720 #QUIET
1 #LET([D11]=[A0])
2 #LET([B0]=1)
3 #LABEL(FACTLOOP)
4 #IF([D11]>1)
5 #THEN
6 #LET([B0]=[B0]*[D11])
7 #DECR([D11])
8 #BRANCH(FACTLOOP)
9 #ENDIF
10 #RETURN
11 1
This is a primitive macro. It "blows up" when the initial value (A0) is
greater than 33. It's not position-independent code; that is, it will
only calculate the factorial for the value in A0, it will always put it
in B0, and the macro itself must live in D0..D11.
My hope was to not have to use a macro. Unfortunately, I don't think
there's any other way.
/Dwayne
| |||||
| 1252.4 | GUESS::DERAMO | Colorado Rocky Mountain high | Tue Jun 12 1990 23:02 | 5 | |
Perhaps he can initialize a row or column of a
spreadsheet to the proper values (up to where they
overflow), and import the correct cell when he needs it.
Dan
| |||||