HP42s first major program (Double Integral) Best way to approach?
|
06-19-2020, 01:46 AM
Post: #61
|
|||
|
|||
RE: HP42s first major program (Double Integral) Best way to approach? | |||
06-19-2020, 01:50 AM
Post: #62
|
|||
|
|||
RE: HP42s first major program (Double Integral) Best way to approach?
(06-19-2020 01:46 AM)Thomas Okken Wrote:(06-19-2020 01:01 AM)DM48 Wrote: In Werner's program below, is there anyway to make LBL "FX" into a local label? I keep trying to turn FX into 11 but this gives an error. Thanks Thomas. I was afraid that would be the case. HP48GX, HP42s and DM42. |
|||
06-19-2020, 07:39 AM
(This post was last modified: 06-19-2020 08:12 AM by Werner.)
Post: #63
|
|||
|
|||
RE: HP42s first major program (Double Integral) Best way to approach?
No need to be afraid..
Code: 00 { 96-Byte Prgm } Cheers, Werner 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
06-19-2020, 05:42 PM
(This post was last modified: 06-19-2020 06:30 PM by DM48.)
Post: #64
|
|||
|
|||
RE: HP42s first major program (Double Integral) Best way to approach?
Werner! You never cease to blow my mind. I assumed, incorrectly I see, that the first Global Label was the name of the program. Thank you for showing me this doesn't have to be the case.
HP48GX, HP42s and DM42. |
|||
06-19-2020, 10:42 PM
Post: #65
|
|||
|
|||
RE: HP42s first major program (Double Integral) Best way to approach?
There’s only one global label here, but it doesn’t have to be the first line in the program; it saved three bytes this way! Old habits die hard ;-)
Werner 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
06-19-2020, 10:55 PM
Post: #66
|
|||
|
|||
RE: HP42s first major program (Double Integral) Best way to approach?
Strictly speaking, programs don't have names. They can contain zero or more global labels, but most functions that take labels as arguments refer to that specific label, not to the program as a whole. This applies to GTO, XEQ, PGMINT, VARMENU, and most others.
The only exceptions, where a function does refer to an entire program, meaning, everything following the previous program's END (or the start of memory, in the case of the first program in memory) until the END, are the CLP and PRP functions, and for those functions, it does not matter which label within a program you choose. |
|||
06-20-2020, 02:06 PM
Post: #67
|
|||
|
|||
RE: HP42s first major program (Double Integral) Best way to approach?
(06-19-2020 10:42 PM)Werner Wrote: There’s only one global label here, but it doesn’t have to be the first line in the program; it saved three bytes this way! Old habits die hard ;-) I find it very slick you used the VARMENU with MVAR. Learning something new everyday. HP48GX, HP42s and DM42. |
|||
06-20-2020, 04:23 PM
(This post was last modified: 10-23-2020 09:01 PM by Albert Chan.)
Post: #68
|
|||
|
|||
RE: HP42s first major program (Double Integral) Best way to approach?
(06-13-2020 10:16 PM)Albert Chan Wrote: Inspired by Werner's AGM code thread, I fixed my AGM2 convergence issue. To improve agm2 accuracy, I redefined agm2 returns: x, y = agm2(a, b) → x = converged GM of agm(a, b) → y = -Σ(2k (½gapk)² , k = 1 .. n), n = number of iterations to converge GM With this new setup, ellipse_perimeter(a,b) = 4 a E(1-(b/a)²) = pi (y + b² + a²)/x Example: for ellipse perimeter, a=50, b=10 50 Enter 10 XEQ "AGM" [X<>Y] 10 [X↑2] + 50 [X↑2] + [X<>Y] ÷ ; ellipse "diameter" ≈ 66.8770488614 PI × ; ellipse perimeter ≈ 210.100445397 For E(m), K(m): x, y = agm2(1, sqrt(1-m)) → K = pi / (2*x) → E = K * (y + (1-m) + 1²) / 2 = K + K*(y-m)/2 Instead of returning (E, K), it is better to return (K, E-K), keeping the accurate difference. (for 0 < m < 1, y is negative, E-K = K*(y-m)/2 avoided subtraction cancellation errors) Again, for ellipse_perimeter, a=50, b=10, e² = 1-(b/a)² = 0.96 0.96 XEQ "K" + 200 × ; ellipse perimeter ≈ 210.100445397 Below is updated EK based HV, and K/AGM code Code: 00 { 65-Byte Prgm } Code: 00 { 92-Byte Prgm } (06-08-2020 12:11 AM)Albert Chan Wrote: HV(1,1000) = 785.3980652226656130844841050849260, error = -2 ULP This updated version matched accuracy of my EKmc based HV. With EK based HV(1,1000), I get: 785.3980652226656130844841050849257 |
|||
06-20-2020, 04:29 PM
Post: #69
|
|||
|
|||
RE: HP42s first major program (Double Integral) Best way to approach?
24 decimal precision (did I count correctly)? Wow!
HP48GX, HP42s and DM42. |
|||
06-21-2020, 01:03 PM
(This post was last modified: 10-23-2020 09:02 PM by Albert Chan.)
Post: #70
|
|||
|
|||
RE: HP42s first major program (Double Integral) Best way to approach?
(06-20-2020 04:23 PM)Albert Chan Wrote: x, y = agm2(1, sqrt(1-m)) We can also move up the agm2 chain, and do this (note, m=d²) x0, y0 = agm2(1+d, 1-d) → K = pi / (2*x0) → E = K + K*y0/4 → HV1 = (m*(E+K) + (E-K))/3 = pi/(24*x0) * (y0*(m+1) + 8*m) We can get HV without E, K, not even sqrt, only agm2. For example, HV(1, 1000) lua> d, D = 1, 1000 lua> d2, D2 = d*d, D*D lua> x, y = agm2(D+d, abs(D-d)) lua> pi/(24*x) * (y*(d2+D2) + 8*d2*D2) -- HV(d,D) 785.3980652226655 Note the symmetry of HV formula, it does not require d ≤ D (no sorting ) Code: 00 { 71-Byte Prgm } |
|||
06-22-2020, 06:36 AM
Post: #71
|
|||
|
|||
RE: HP42s first major program (Double Integral) Best way to approach?
(06-20-2020 04:29 PM)DM48 Wrote: 24 decimal precision (did I count correctly)? Wow!No, 34 digits! Werner 41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE |
|||
06-27-2020, 12:35 PM
(This post was last modified: 06-27-2020 01:47 PM by Albert Chan.)
Post: #72
|
|||
|
|||
RE: HP42s first major program (Double Integral) Best way to approach?
(06-06-2020 08:33 PM)Albert Chan Wrote:(06-02-2020 08:31 AM)Werner Wrote: Question: wouldn't the formula need to be We can prove this with Legendre's relation, 19.7.3 Note: the prove use elliptical parameter m instead of modulus, k, m = k² Assume d < D = 1, so that m = (d/D)² = d² < 1 (we can scale it back later, by factor D³) 3*HV(d,1) = m*(E+K) + (E-K) = (m+1)*E + (m-1)*K With order flipped, using notation K(1/m) = K(m) , K(1-m) = K'(m) 3*HV(1,d) = d³ * 3*HV(1/d,1) = d³ * ((1/m+1)*E + (1/m-1)*K) = (m+1) * (d*E) + (m-m²) * (K/d) = (m+1) * (E - (1-m)*K ± 1j * (E' - m*K')) + (m-m²) * (K ∓ 1j * K') Re(3*HV(1,d)) = (m+1)*E + (m²-1)*K + (m-m²)*K = 3*HV(d,1) Adding the special case, HV(1,1) = 2/3, and removed assumptions d < D = 1: hole volume = Re(HV(d,D)) = Re(HV(D,d)) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 21 Guest(s)