(45) Straight-Line Fitting
|
01-31-2020, 12:34 PM
Post: #1
|
|||
|
|||
(45) Straight-Line Fitting
The Hewlett-Packard HP-45 pocket calculator includes a key ∑+ that accumulates and stores the sums ∑1(=n), ∑x, ∑x², and ∑y, with another key that directs the calculator to compute the mean of x and its standard deviation. An independent y entry can be summed simultaneously.
Another problem occurring often in data reduction is to find the least-squares slope and intercept of a straight line and their standard deviations. For this case the sums ∑xy and ∑y² are needed, in addition to those provided by the ∑+ key. An efficient (though not unique) procedure for accumulating the necessary sums with the HP-45 is the following: In succession, key in the data pairs (xi, yi) together with keyboard steps in the order: xi, ENTER↑, ENTER↑, yi, ENTER↑, STO + 3, X², STO + 4, R↓, ×, x⇄y, ∑+. After processing all data pairs in this manner the sums can be recalled from storage as needed, with ∑y in R3, ∑y² in R4, n in R5, ∑x² in R6, ∑x in R7 and ∑xy in R8. It is then a simple task to calculate the slope, intercept, and standard deviations using the well-known least-squares formulas. If the standard deviations are not required, the sum ∑y² can be omitted, with a saving of six keyboard steps (steps 5, 9, 10, 11, 12, 13 in the previous list). source: AJP Volume 42, COMPUTER NOTES, Straight-Line Fitting with an HP-45 Calculator, W. C. ELMORE (Swarthmore College), April 1974, pg. 253 BEST! SlideRule |
|||
03-10-2024, 02:26 PM
Post: #2
|
|||
|
|||
RE: (45) Straight-Line Fitting
(01-31-2020 12:34 PM)SlideRule Wrote: If the standard deviations are not required, the sum ∑y² can be omitted, with a saving of six keyboard steps (steps 5, 9, 10, 11, 12, 13 in the previous list). This leaves us with:
But we can do slightly better with:
Registers These registers are used: \( \begin{array}{|c|c|} \hline \text{Register} & \text{Value} \\ \hline 1 & a \\ 2 & b \\ 3 & \sum{y} \\ 5 & n \\ 6 & \sum{x^2} \\ 7 & \sum{x} \\ 8 & \sum{xy} \\ \hline \end{array} \) Formula (01-31-2020 12:34 PM)SlideRule Wrote: It is then a simple task to calculate the slope, intercept, and standard deviations using the well-known least-squares formulas. The following formulas are used to calculate slope \(a\) and intercept \(b\): \( \begin{align} a &= \frac{\sum{xy} - \frac{\sum{x} \sum{y}}{n}}{\sum{x^2} - \frac{\sum{x}^2}{n}} \\ \\ b &= \frac{\sum{y} - a \cdot \sum{x}}{n} \\ \end{align} \) Program These steps calculate both \(a\) and \(b\): Code: # calculate a Example \( \begin{array}{|c|c|c|c|c|c|c|} \hline n & 1 & 2 & 3 & 4 & 5 & 6 \\ \hline C & 40.5 & 38.6 & 37.9 & 36.2 & 35.1 & 34.6 \\ \hline F & 104.5 & 102 & 100 & 97.5 & 95.5 & 94 \\ \hline \end{array} \) Initialise the Registers CLEAR STO 3 Enter the Data 104.5 STO + 3 40.5 × LASTx Σ+ 102 STO + 3 38.6 × LASTx Σ+ 100 STO + 3 37.9 × LASTx Σ+ 97.5 STO + 3 36.2 × LASTx Σ+ 95.5 STO + 3 35.1 × LASTx Σ+ 94 STO + 3 34.6 × LASTx Σ+ Result RCL 1 1.76 RCL 2 33.53 HP-25 The statistics functions also store \(\sum{xy}\). In addition to that it is programmable. Both makes entry of the data and calculating the best fit much easier. Initialise the Registers CLEAR REG Enter the Data 104.5 ENTER 40.5 Σ+ 102 ENTER 38.6 Σ+ 100 ENTER 37.9 Σ+ 97.5 ENTER 36.2 Σ+ 95.5 ENTER 35.1 Σ+ 94 ENTER 34.6 Σ+ Program Code: 01: 24 04 : RCL 4 Data Code: DATA Python Just in case you want to compare the results: Code: C = [40.5, 38.6, 37.9, 36.2, 35.1, 34.6] (1.7601490488333176, 33.52712950250892, 222.9, 593.5, 8306.23, 22093.4, 6) References
|
|||
03-11-2024, 11:28 AM
Post: #3
|
|||
|
|||
RE: (45) Straight-Line Fitting
And that is why I bought the HP-55 in 1975 as my first HP calculator because it had built-in linear regresssion! Earlier that year, I had done linear regression (ln(y) vs 1/(x+constant)) calculations on a Sharp scientific calculator with one memory register ... and I swore it was the first and last time I do linear regression in that painfull way!!!
Namir |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)