16 Point Gaussian Quadrature for the HP-41C/CV/CX (updated)
|
11-09-2023, 09:23 PM
(This post was last modified: 11-15-2023 10:42 PM by Namir.)
Post: #1
|
|||
|
|||
16 Point Gaussian Quadrature for the HP-41C/CV/CX (updated)
16 Point Gaussian Quadrature for the HP-41C/CV/CX (updated)
This program is a slightly enhanced version of the one posted by Tony Udell. The program includes LBL 00 that initializes the values for the quadrature nodes and weights. I have also remapped the memory registers into a contiguous sequence from 00 to 19. You can download the .raw program file by clicking here. To use the program: 1) Press [A] to perform a regular integration between A and B. The program prompts you for the values of A and B. Enter these values and press [R/S] to calculate the integral. 2) Press [B] to perform a special integration between A and infinity. The program prompts you for the value of A. Enter the value and press [R/S] to calculate the integral. Notes: 1) Label "FX" (also label E) is where you enter the statements to evaluate the integrated function. 2) The program automatically calls subroutine at LBL 00 to initialize the nodes and weights for the quadrature. Memory Map ========== Code: R00 = integral Program Listing ============ Code: 01 LBL "A-B" Example 1 ========= To calculate the integral of 1/x from 1 to 2 (which is equal to ln(2)): 1. In program mode insert the command 1/x after LBL E and make sure it is followed by RTN. 2. In run mode (user mode on) clear flag 1 using [f][CF][0][1]. Skip this step if you are not running the program the first time. 3. Press the [A] key. 4. The program prompts you to enter the value of "a". Enter 1 and press the [R/S] key. 5. The program prompts you to enter the value of "b". Enter 2 and press the [R/S] key. 6. The program displays 0.69315 (FIX 9 displays 0.693147181) as the value of the integral. Example 2 ======== To calculate the integral of exp(-x)*x^0.8 from 0 to inifinity (which is equal to gamma(1.8)): 1. In program mode insert the commands CHS, EXP, LASTX, CHS, 0.8, Y^X and, * after LBL E and make sure it is followed by RTN. 2. In run mode (user mode on) clear flag 1 using [f][CF][0][1]. Skip this step if you are not running the program the first time. 3. Press the [A] key. 4. The program prompts you to enter the value of "a". Enter 0 and press the [R/S] key. 5. The program displays 0.93138 (FIX 9 displays 0.931378447) as the value of the integral. |
|||
11-09-2023, 10:39 PM
Post: #2
|
|||
|
|||
RE: 16 Point Gaussian Quadrature for the HP-41C/CV/CX (updated) | |||
11-10-2023, 01:11 AM
Post: #3
|
|||
|
|||
RE: 16 Point Gaussian Quadrature for the HP-41C/CV/CX (updated)
.
Hi, Namir, There's a number of errors in your program's listing, namely wrong numeration of the lines marked in red below: Namir Wrote: Besides, several of your 10-digit numeric coefficients below marked in red are wrong or inaccurate ... Namir Wrote:120 2.715245941E-2 ... so you'd do well getting the correct/accurate values from a reputable source and/or typing them correctly. Finally, if you'd take a friendly advice, when posting a program which performs such a computation, it would be proper (nay, mandatory) to include some numeric results generated by the program, if nothing else just that people trying it out can be reassured that it's correctly loaded and properly working by simply running your program and actually getting exactly your results. Regards. V. All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
11-10-2023, 03:18 AM
Post: #4
|
|||
|
|||
RE: 16 Point Gaussian Quadrature for the HP-41C/CV/CX (updated)
Thanks Valentin. The errors were generated when I was renaming registers. This process afected some line numbers and some of the numerical constants. Fortunately, I wrote the program first, saved it as a .raw file, read it with a free42 emulator, print it, and then edited it. So the .raw file in the link should be correct.
Will be adding examples for using the program. Again, Thanks! Namir |
|||
11-10-2023, 11:37 AM
Post: #5
|
|||
|
|||
RE: 16 Point Gaussian Quadrature for the HP-41C/CV/CX (updated)
(11-09-2023 10:39 PM)Albert Chan Wrote:(11-09-2023 09:23 PM)Namir Wrote: 2) Press [B] to perform a special integration between A and infinity. Th approximation for the integral uses: integral = 2 * sum of (w(i)/(1+x(i))^2 * fx(2/(1+x(i)) + A - 1)) for i=1,..., 6 where x(i) are the node values and w(i) are the corresponging weights. The limit 6 can be different, adding more points to get more accurate approximations for the integral. |
|||
11-10-2023, 12:01 PM
Post: #6
|
|||
|
|||
RE: 16 Point Gaussian Quadrature for the HP-41C/CV/CX (updated)
I added two examples.
|
|||
11-10-2023, 05:28 PM
Post: #7
|
|||
|
|||
RE: 16 Point Gaussian Quadrature for the HP-41C/CV/CX (updated)
Hi Namir,
thank you for sharing. Example 1 works fine but I cannot get to a result of example 2. When using example 2 with SST at line 101 I get -0.89474 in the x-register. This goes to the function FX resulting in (-0.89474)^0.8 terminating the program with "DATA ERROR". Can you help? Thank you very much. |
|||
11-10-2023, 11:21 PM
(This post was last modified: 11-11-2023 02:58 AM by Namir.)
Post: #8
|
|||
|
|||
RE: 16 Point Gaussian Quadrature for the HP-41C/CV/CX (updated)
(11-10-2023 05:28 PM)rawi Wrote: Hi Namir, Did you deete the command 1/X in the original listing, before you enter the commands for Example 2? You might also want to try downloading the .raw file and importing it into the HP-41CX emulator from TOS. You can also try to import the code with free42. In the latter case you may want to edit labels A and B to add another letter/digit like AA and BB pr A1 and B1. Namir |
|||
11-11-2023, 07:11 AM
Post: #9
|
|||
|
|||
RE: 16 Point Gaussian Quadrature for the HP-41C/CV/CX (updated)
(11-10-2023 03:18 AM)Namir Wrote: Will be adding examples for using the program. You're welcome. Also, you posted these two results: Quote:Example 1 Both were posted as 5-digit values. Could you please post these two results to full 10-digit accuracy ? It would be necessary to gauge the correctness of your program/data in order to detect any further errors and, again, for people using your program to check that they do exactly obtain your results to full 10-digit precision. Regards. V. All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
11-11-2023, 08:38 AM
Post: #10
|
|||
|
|||
RE: 16 Point Gaussian Quadrature for the HP-41C/CV/CX (updated)
Thanks for your fast reply!
Namir wrote: Quote:Did you deete the command 1/X in the original listing, before you enter the commands for Example 2? Yes, I did. Quote:You might also want to try downloading the .raw file and importing it into the HP-41CX emulator from TOS. You can also try to import the code with free42. In the latter case you may want to edit labels A and B to add another letter/digit like AA and BB pr A1 and B1. I tried to download but got a message, that it cannot be downloaded safely. |
|||
11-11-2023, 11:43 AM
Post: #11
|
|||
|
|||
RE: 16 Point Gaussian Quadrature for the HP-41C/CV/CX (updated)
(11-11-2023 08:38 AM)rawi Wrote: Thanks for your fast reply! I checked the listed code (for the integration between A and infinity) with that in my 41CX emulator and found no errors or differences. Namir |
|||
11-11-2023, 01:38 PM
Post: #12
|
|||
|
|||
RE: 16 Point Gaussian Quadrature for the HP-41C/CV/CX (updated) | |||
11-11-2023, 03:41 PM
Post: #13
|
|||
|
|||
RE: 16 Point Gaussian Quadrature for the HP-41C/CV/CX (updated)
Thank you Namir and John,
now the download of the .raw file was successful and the program works fine. Especially the integration to infinity is somethong that is very useful since it is not included in the integration programs used in HP 15C, HP 42S or the Advantage module. And it is very exact: The upper tail of the normal distribution from 1.96 to infinity is computed as 0.02499792 whereas the exact value is 0.02499790. |
|||
11-11-2023, 06:59 PM
Post: #14
|
|||
|
|||
RE: 16 Point Gaussian Quadrature for the HP-41C/CV/CX (updated)
(11-11-2023 03:41 PM)rawi Wrote: Thank you Namir and John, Good to hear that! Thanks! Namir |
|||
11-12-2023, 01:49 AM
Post: #15
|
|||
|
|||
RE: 16 Point Gaussian Quadrature for the HP-41C/CV/CX (updated)
.
Hi, Namir, Would you please post the two values as I asked in Message #9 above ? Thanks in advance. V. All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
11-12-2023, 04:22 AM
Post: #16
|
|||
|
|||
RE: 16 Point Gaussian Quadrature for the HP-41C/CV/CX (updated)
(11-12-2023 01:49 AM)Valentin Albillo Wrote: . I updated the original post to indicate what FIX 9 would show for both examples. |
|||
11-12-2023, 05:32 AM
(This post was last modified: 11-12-2023 05:33 AM by Valentin Albillo.)
Post: #17
|
|||
|
|||
RE: 16 Point Gaussian Quadrature for the HP-41C/CV/CX (updated)
(11-12-2023 04:22 AM)Namir Wrote:(11-12-2023 01:49 AM)Valentin Albillo Wrote: Would you please post the two values as I asked in Message #9 above ? Yes, I noticed, but I need to know all 10-digit mantissas, not just 9-digit. A simple way to obtain them in FIX 9 is once your program outputs rhe result, multiply it by 10 (i.e. 10, *). This will show all 10 digits present. Please do and post a new message here with both 10-digit results, don't update the original post. Again, thanks in advance. V. All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
11-12-2023, 08:38 AM
Post: #18
|
|||
|
|||
RE: 16 Point Gaussian Quadrature for the HP-41C/CV/CX (updated)
(11-12-2023 05:32 AM)Valentin Albillo Wrote:(11-12-2023 04:22 AM)Namir Wrote: I updated the original post to indicate what FIX 9 would show for both examples. Example 1 0.6931471810 Example 2 0.9313784470 |
|||
11-12-2023, 03:24 PM
Post: #19
|
|||
|
|||
RE: 16 Point Gaussian Quadrature for the HP-41C/CV/CX (updated)
(11-12-2023 08:38 AM)Namir Wrote:(11-12-2023 05:32 AM)Valentin Albillo Wrote: Yes, I noticed, but I need to know all 10-digit mantissas, not just 9-digit. A simple way to obtain them in FIX 9 is once your program outputs rhe result, multiply it by 10 (i.e. 10, *). This will show all 10 digits present. Please do and post a new message here with both 10-digit results, don't update the original post. Both values end in 0 ? Really ? It's a 1-in-100 chance. Did you multiply them by 10 as I suggested ? If yes, then they'd be like 6.93... and 9.31... respectively, not the 0.693... and 0.931... values you posted. Could you please check them out one final time ? Thanks and regards. V. All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
11-12-2023, 05:33 PM
Post: #20
|
|||
|
|||
RE: 16 Point Gaussian Quadrature for the HP-41C/CV/CX (updated)
(11-12-2023 03:24 PM)Valentin Albillo Wrote:(11-12-2023 08:38 AM)Namir Wrote: Example 1 0.6931471810 Yes I multiplied both results by 10 ans then moved the decimal to the right, so they correspond to the original answers (now with 10 digits).. Using MATLAB, I calculated log(2) (the integral of 1/x from 1 to 2) and got 0.693147180559945. Comparing this result with what I got on the HP-41CX, looks like the 41CX rounded the part of 8055 into 810. I assume the calculator might have done similar rounding to the result of Example 2. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 6 Guest(s)