Integral in solve on HP 42S? - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: General Forum (/forum-4.html) +--- Thread: Integral in solve on HP 42S? (/thread-12495.html) Integral in solve on HP 42S? - lrdheat - 02-24-2019 06:29 PM If I wanted to, say, find what "x" would satisfy the integral of x^2 from 0 to x such that the area under the curve equaled 10, can this be accomplished in solve on an HP 42S? RE: Integral in solve on HP 42S? - Thomas Klemm - 02-24-2019 08:13 PM Code: ```00 { 12-Byte Prgm } 01▸LBL "f" 02 MVAR "t" 03 RCL "t" 04 X↑2 05 END``` Code: ```00 { 28-Byte Prgm } 01▸LBL "∫f" 02 MVAR "x" 03 RCL "x" 04 STO "ULIM" 05 PGMINT "f" 06 INTEG "t" 07 10 08 - 09 END``` You can set LLIM and ACC: 0 STO "LLIM" 1e-10 STO "ACC" And then just use the SOLVER with the program ∫f and the variable x to get 3.10723250595 Cheers Thomas RE: Integral in solve on HP 42S? - lrdheat - 02-24-2019 08:15 PM Easy! Thanks. RE: Integral in solve on HP 42S? - Gerald H - 02-25-2019 05:17 AM (02-24-2019 08:13 PM)Thomas Klemm Wrote:   Code: ```00 { 12-Byte Prgm } 01▸LBL "f" 02 MVAR "t" 03 RCL "t" 04 X↑2 05 END``` Code: ```00 { 28-Byte Prgm } 01▸LBL "∫f" 02 MVAR "x" 03 RCL "x" 04 STO "ULIM" 05 PGMINT "f" 06 INTEG "t" 07 10 08 - 09 END``` You can set LLIM and ACC: 0 STO "LLIM" 1e-10 STO "ACC" And then just use the SOLVER with the program ∫f and the variable x to get 3.10723250595 Cheers Thomas Line 002 of programme f is not essential. RE: Integral in solve on HP 42S? - Werner - 02-25-2019 07:43 AM (02-25-2019 05:17 AM)Gerald H Wrote:  Line 002 of programme f is not essential. Indeed not - MVAR statements are only used by the interactive solve and integrate. Moreover, you can replace Code: ```02 MVAR "x" 03 RCL "x" 04 STO "ULIM"``` by Code: `02 MVAR "ULIM"` straight away and solve for ULIM. Cheers, Werner RE: Integral in solve on HP 42S? - Thomas Klemm - 02-25-2019 07:47 AM (02-25-2019 05:17 AM)Gerald H Wrote:  Line 002 of programme f is not essential. We can also drop line 05 of program ∫f: Code: `05 PGMINT "f"` We just have to execute it once manually: PGMINT "f" This also allows to use the program ∫f with different functions without having to change the code. Cheers Thomas RE: Integral in solve on HP 42S? - Thomas Klemm - 02-25-2019 08:09 AM So we end up with: Code: ```00 { 9-Byte Prgm } 01▸LBL "f" 02 RCL "x" 03 X↑2 04 END``` Code: ```00 { 19-Byte Prgm } 01▸LBL "∫f" 02 MVAR "ULIM" 03 INTEG "x" 04 10 05 - 06 END``` Example: 0 STO "LLIM" 1e-10 STO "ACC" PGMINT "f" Then use the SOLVER with the program ∫f and the variable ULIM to get 3.10723250595 Cheers Thomas RE: Integral in solve on HP 42S? - lrdheat - 02-26-2019 03:15 AM It is fun (and instructive) to see how concise coding can be accomplished. I'm always fascinated and impressed. Wondered if the HP 42S could integrate the maximum of (f(x), g(x)) over some interval. Quite easy! For max (sin(x), cos(x)), all that was necessary was to take sin(x), x<>y, cos(x), if x>=y, RTN, x<>y, END I will begin to try-relearn indirect addressing (last did this on an HP 67 in the 1970's when I programmed a simple baseball game...had lineups and data of 1970 American League teams on the magnetic cards, and used indirect addressing to remember where in the lineup I was at). Then, try to refresh my knowledge on the usage of flags! RE: Integral in solve on HP 42S? - Thomas Okken - 02-26-2019 03:30 AM (02-26-2019 03:15 AM)lrdheat Wrote:  I will begin to try-relearn indirect addressing (last did this on an HP 67 in the 1970's You're in for a treat, then! I have no experience with the HP-67 myself (I own one now, purchased on eBay, but couldn't have afforded it back when it was new), but I do have experience with the HP-19C, which is very similar. Both have only one "indirect" register, which makes a lot of algorithms awkward to implement, always having to shuffle things around to get the right pointer into register 0 (which is the I equivalent on the 19C and 29C). Compared to that, programming the 41C, where every register, even the stack registers, can be used for indirect addressing, is so much more pleasant, and the 42S inherited that programming model. RE: Integral in solve on HP 42S? - Thomas Klemm - 02-26-2019 05:30 AM (02-26-2019 03:30 AM)Thomas Okken Wrote:  Both have only one "indirect" register, which makes a lot of algorithms awkward to implement, always having to shuffle things around to get the right pointer into register 0 (which is the I equivalent on the 19C and 29C). Compared to that, programming the 41C, where every register, even the stack registers, can be used for indirect addressing, is so much more pleasant, and the 42S inherited that programming model. From Calculator Speed Benchmark using the N-Queens Problem: HP-67 Code: ``` LBL A  CLEAR REG         8 STO A  LBL 0  RCL 0 RCL A         x=y? GTO 4         1 STO+ 0         RCL 0 STO I         RCL A STO(i)  LBL 1  RCL B 1 + STO B         RCL 0 STO 9  LBL 2  1 STO- 9         RCL 9 x=0? GTO 0         RCL 0 STO I RCL(i)         RCL 9 STO I         Rv RCL(i) -         x=0? GTO 3         ABS RCL 0 RCL 9 -         x<>y? GTO 2  LBL 3  RCL 0 STO I         1 STO-(i)         RCL(i) x<>0? GTO 1         1 STO- 0         RCL 0 x<>0? GTO 3  LBL 4  RCL B         RTN``` HP-41 Code: ``` LBL A   CLRG          8 STO 11  LBL 00  RCL 00 RCL 11          X=Y? GTO 04          ISG 00 DEG          STO IND 00  LBL 01  ISG 10 DEG          RCL 00 STO 09  LBL 02  DSE 09 DEG          RCL 09 X=0? GTO 00          RCL IND 00 RCL IND 09 -          X=0? GTO 03          ABS RCL 00 RCL 09 -          X<>Y? GTO 02  LBL 03  DSE IND 00 GTO 01          DSE 00 GTO 03  LBL 04  RCL 10          RTN``` Compare e.g. the inner loop between LBL 2 … GTO 2: HP-67 Code: ```        RCL 0 STO I RCL(i)         RCL 9 STO I         Rv RCL(i) -``` HP-41 Code: `         RCL IND 00 RCL IND 09 -` Cheers Thomas RE: Integral in solve on HP 42S? - Werner - 02-26-2019 07:41 AM (02-25-2019 08:09 AM)Thomas Klemm Wrote:  So we end up with: Code: ```00 { 9-Byte Prgm } 01▸LBL "f" 02 RCL "x" 03 X↑2 04 END``` Code: ```00 { 19-Byte Prgm } 01▸LBL "∫f" 02 MVAR "ULIM" 03 INTEG "x" 04 10 05 - 06 END``` Example: 0 STO "LLIM" 1e-10 STO "ACC" PGMINT "f" Then use the SOLVER with the program ∫f and the variable ULIM to get 3.10723250595 Cheers Thomas It would make sense to then add ACC and LLIM as MVARS to "∫f": Code: ```00 { 30-Byte Prgm } 01▸LBL "∫f" 02 MVAR "ACC" 03 MVAR "LLIM" 04 MVAR "ULIM" 05 INTEG "x" 06 10 07 - 08 END``` .. makes it a lot easier to enter the numbers, and to play with different ACC's. Cheers, Werner RE: Integral in solve on HP 42S? - ijabbott - 02-26-2019 08:39 AM (02-26-2019 07:41 AM)Werner Wrote:  It would make sense to then add ACC and LLIM as MVARS to "∫f": Code: ```00 { 30-Byte Prgm } 01▸LBL "∫f" 02 MVAR "ACC" 03 MVAR "LLIM" 04 MVAR "ULIM" 05 INTEG "x" 06 10 07 - 08 END``` .. makes it a lot easier to enter the numbers, and to play with different ACC's. Cheers, Werner Would anyone want to SOLVE for ACC though? A useful thing to add would be the (signed) area, which is fixed at 10 in the above versions of ∫f. RE: Integral in solve on HP 42S? - Gerald H - 02-26-2019 09:29 AM This is how I did the calculation for Normal distribution. First set accuracy by entering number of decimal digits accuracy required, eg 4 then activate FXACC Code: ```0.     { 21-Byte Prgm } 1.    ►LBL "FXACC" 2.     FIX IND ST X 3.     +/- 4.     10^X 5.     STO "ACC" 6.     CLX 7.     LASTX 8.     +/- 9.     END``` to set accuracy to 0.0001 To find probability from Z value, enter Z & activate Z→P, & to find Z value , enter P & activate P→Z. Code: ```0.     { 26-Byte Prgm } 1.    ►LBL "ΣDPREP" 2.     STO "ULIM" 3.     CLX 4.     STO "LLIM" 5.     INTEG "x" 6.     END 0.     { 96-Byte Prgm } 1.    ►LBL "NPDF" 2.     RCL "x" 3.     X^2 4.     -2 5.     ÷ 6.     E^X 7.     RTN 8.    ►LBL "Z→P" 9.     PGMINT "NPDF" 10.    ►LBL 00 11.     XEQ "ΣDPREP" 12.     PI 13.     RCL+ ST X 14.     SQRT 15.     ÷ 16.     0.5 17.     X<>Y 18.     - 19.     RTN 20.    ►LBL "?Z" 21.     RCL "z" 22.     XEQ 00 23.     RCL- 00 24.     RTN 25.    ►LBL "P→Z" 26.     PGMINT "NPDF" 27.     STO 00 28.     PGMSLV "?Z" 29.     4 30.     STO "z" 31.     SIGN 32.     SOLVE "z" 33.     END```