How do I learn RPL and solve this problem with it?
|
09-25-2017, 08:04 PM
Post: #21
|
|||
|
|||
RE: How do I learn RPL and solve this problem with it?
I have not read the whole thread, but I'm wondering if the fact that the base resistor values form a, more or less, geometric series is used in some way.
Thus, the E12 series uses 12 values on each decade, this way the ratio between one value and the next is \(\sqrt[12]{10}=1.2115\ldots\). This way the E12 values are:
I'm not yet worked this, but perhaps it would be possible to only search for resistor pairs that are zero steps apart, then one, then two,... and so on. Regards. |
|||
09-25-2017, 08:17 PM
Post: #22
|
|||
|
|||
RE: How do I learn RPL and solve this problem with it?
What a fantastic problem!!!
For UserRPL programming, download HPUserEdit 6 from hpcalc.org. Also download the file that converts the menus etc into English since the original is in... Spanish? HPUserEdit will let you write and debug your programs on the PC. If your 50g came with the 184 page "User's Manual" then you should lock that book securely in a safe for now. It's more like a quick reference quide and will only serve to confuse you as a beginner. Use the "User's Guide" instead. It has much more detail. The biggest problem with the User's Guide has to do with the 4 major modes of operation of the 50g: RPN vs. Algebraic input, and Soft Menus vs. choose boxes. Because of these modes, the User's Guide is full of things that say: Now to do XYZ in RPN mode, enter these keys (half-page examples follows). If you're using algebraic mode, do this (another half page example follows). The above assume that you're using choose boxes. If you have soft menus, your screens will look like this... and this... For this reason, you might want to consider using the 48GX User's Guide instead. It's all RPN and all soft menus. |
|||
09-25-2017, 08:27 PM
Post: #23
|
|||
|
|||
RE: How do I learn RPL and solve this problem with it?
(09-25-2017 06:36 PM)mfleming Wrote: Hi guys, I agree, there's 4 or 5 valid values, no need to precompute anything. The basic tasks can be broken into:
Note that 1, 2 and 4 are basically the same, lookup the E12 resistor given a value, but in one case get the lower bound, in the other the upper and the third is closest match. Perhaps a single routine can handle all 3 cases. Task #3 can also reuse the same routine, since the next valid resistor would be the closest match to R*1.211 (with R being a valid E12 resistor). That's the simplest way I see it. And that's not taking anybody by the hand, as each task is a project on itself. So the first goal would be a routine that given any value, finds the lower, upper and closest match in the E12 series. |
|||
09-26-2017, 01:02 AM
Post: #24
|
|||
|
|||
RE: How do I learn RPL and solve this problem with it?
I'm no good at the mathematics behind all this, I've been a bit lost. However, I realised that there's also a real-world value of each resistor, not just a theoretic L<R<U where L and U are the lower/upper 5% bounds. As soon as you add a resistor which ALSO has that same 5% tolerance, you have to hope that for an exact match, your chosen resistors aren't both at the lower edges of their tolerance bands (or higher edges) affecting how close their real (not nominal) value will be to the required theoretic value. Will the two resistors that are low still fall within 5% of the combined value? Ditto for two high resistors in parallel or series.
(Post 99) Regards, BrickViking HP-50g |Casio fx-9750G+ |Casio fx-9750GII (SH4a) |
|||
09-26-2017, 06:03 AM
Post: #25
|
|||
|
|||
RE: How do I learn RPL and solve this problem with it?
(09-25-2017 08:27 PM)Claudio L. Wrote: - cut - About the resistors in series, I realized since a while (without proof) that likely one goes picking the largest one that fits the value and then the second largest that first the remaining value. I guess this approach won't be that valid with 3+ resistors, because the algorithm described above is greedy. For the parallel resistors, I did not analyse the formula (I just took it as it is), but now I realize that is pretty the same - and very close to egyptian fractions indeed. I take the value that fits closer to 1/R and then the value that is closer to the remaining value. Once again, this should work because the values to pick are two. Would they be more, then it would be more challenging. Thus the list of resistor precomputed surely speeds up the problem, but it is not needed to have all the combination precomputed (although it is a nice challenge of packing that data on the 50g). Anyway both ways are interesting, the naive "don't let me think about the formula" brings certain challenges due to the scale of the problem, the more pondered "ok let's see what could be a shorter way" bring the challenge to verify that certain observations/decisions works (best case: a proof, worst case: check against all the possible combinations) Wikis are great, Contribute :) |
|||
09-26-2017, 12:06 PM
Post: #26
|
|||
|
|||
RE: How do I learn RPL and solve this problem with it?
(09-26-2017 01:02 AM)brickviking Wrote: I'm no good at the mathematics behind all this, I've been a bit lost. However, I realised that there's also a real-world value of each resistor, not just a theoretic L<R<U where L and U are the lower/upper 5% bounds. As soon as you add a resistor which ALSO has that same 5% tolerance, you have to hope that for an exact match, your chosen resistors aren't both at the lower edges of their tolerance bands (or higher edges) affecting how close their real (not nominal) value will be to the required theoretic value. Will the two resistors that are low still fall within 5% of the combined value? Ditto for two high resistors in parallel or series. This is an important point. Also, standard 5% resistors have greater thermal variation than 1% resistors, so I don't think it's realistic to try to get a match within 1% of the desired value. IMHO a better definition of the problem is to sort the viable combinations by closeness to the desired value and pick the best one. John |
|||
09-26-2017, 01:02 PM
Post: #27
|
|||
|
|||
RE: How do I learn RPL and solve this problem with it?
I'd solve it like so:
To help with this, you should write (or find) a binary search function for finding a value in an array. I'd call it binSearchLEQ. It finds the closest value that is less than or equal to a given value. It returns the INDEX to the value, not the value itself. That way you can get the next largest item easily. The binary search is why you want to work with an array: finding the N'th value in an array takes constant time, whereas finding the Nth value in a list takes N time. That should be fast enough. A faster way would start at each end of the array and work towards the center. At each step you'd pick a value from one side and then move find the value on the other side that gives the best fit. This way the whole process would make one pass for finding the best serial combination. For parallel combinations it might be more involved. |
|||
09-26-2017, 02:29 PM
Post: #28
|
|||
|
|||
RE: How do I learn RPL and solve this problem with it?
(09-26-2017 01:02 AM)brickviking Wrote: I'm no good at the mathematics behind all this, I've been a bit lost. However, I realised that there's also a real-world value of each resistor, not just a theoretic L<R<U where L and U are the lower/upper 5% bounds. As soon as you add a resistor which ALSO has that same 5% tolerance, you have to hope that for an exact match, your chosen resistors aren't both at the lower edges of their tolerance bands (or higher edges) affecting how close their real (not nominal) value will be to the required theoretic value. Will the two resistors that are low still fall within 5% of the combined value? Ditto for two high resistors in parallel or series. You have a point there. The error in each resistor doesn't really matter much, and here's why: He wants to replace R (with a certain error, let's say 1%) with 2 parallel resistors that also come with a certain error of 1%. 1/R=1/R1+1/R2, therefore let's say both R1 and R2 are at the lower bound of error (the real R1'=0.99*R1, and R2'=0.99*R2) it turns out that: 1/R' = 1/R1'+1/R2' = 1/0.99*(1/R1+1/R2) = 1/(0.99*R) The same will happen if you pick the upper bounds, (just with 1.01 instead of 0.99). In other words, 2 resistors in parallel with a certain tolerance will cause the resulting resistance to be within the same tolerance. However, if the selected pair has an error you'll have that bias + the original tolerance. For example if the selected R1 and R2 produce a value that is 1% higher, you'll have a maximum error of 2% and a minimum of 0%, biased in the same direction. So the user needs to pick the pair that produces the smallest error and accept that little bias, otherwise you'll be forced to use resistors with a smaller tolerance than the original requirement, so the result stays within bounds. But that should be up to the designer, the problem at hand should find all 4 or 5 combinations and present them to the designer. The designer in the end will pick the closest pair, or whatever pair he can find in stock. |
|||
09-26-2017, 02:50 PM
Post: #29
|
|||
|
|||
RE: How do I learn RPL and solve this problem with it?
(09-26-2017 06:03 AM)pier4r Wrote: Thus the list of resistor precomputed surely speeds up the problem, but it is not needed to have all the combination precomputed (although it is a nice challenge of packing that data on the 50g). I wouldn't be so sure it speeds up the problem. You'll be searching through a large list of pairs, which is not necessarily any faster than computing 4 or 5 values on the fly. It's just a couple of additions and divisions versus a long loop of comparisons (only subtractions in the end, but we could be talking in the hundreds until you find all the valid combinations through the list). |
|||
09-26-2017, 02:55 PM
Post: #30
|
|||
|
|||
RE: How do I learn RPL and solve this problem with it?
(09-26-2017 02:50 PM)Claudio L. Wrote: I wouldn't be so sure it speeds up the problem. You'll be searching through a large list of pairs, which is not necessarily any faster than computing 4 or 5 values on the fly. It's just a couple of additions and divisions versus a long loop of comparisons (only subtractions in the end, but we could be talking in the hundreds until you find all the valid combinations through the list). I meant: the list of resistors (that are 96) is good to have in a precomputed form. While the list of all the possible solutions (that should be 9000 items) is not needed. My bad for my poor English, sorry. Wikis are great, Contribute :) |
|||
09-26-2017, 04:37 PM
Post: #31
|
|||
|
|||
RE: How do I learn RPL and solve this problem with it?
(09-25-2017 08:04 PM)emece67 Wrote: I have not read the whole thread, but I'm wondering if the fact that the base resistor values form a, more or less, geometric series is used in some way. Great insight! I know AWG wire diameters follow a geometric progression, but I wasn’t aware of this happening in resistor series. This RPL program will generate all 192 values of the E192 series, if I have verified them correctly: « PUSH -3. SF -105. SF 10. 192. XROOT 191. NDUPN { 1. } 1 ROT FOR i DUP i GET ROT * + NEXT 100. * 0. RND 186. 920. PUT POP » EVAL { 100. 101. 102. 104. 105. 106. 107. 109. 110. 111. 113. 114. 115. 117. 118. 120. 121. 123. 124. 126. 127. 129. 130. 132. 133. 135. 137. 138. 140. 142. 143. 145. 147. 149. 150. 152. 154. 156. 158. 160. 162. 164. 165. 167. 169. 172. 174. 176. 178. 180. 182. 184. 187. 189. 191. 193. 196. 198. 200. 203. 205. 208. 210. 213. 215. 218. 221. 223. 226. 229. 232. 234. 237. 240. 243. 246. 249. 252. 255. 258. 261. 264. 267. 271. 274. 277. 280. 284. 287. 291. 294. 298. 301. 305. 309. 312. 316. 320. 324. 328. 332. 336. 340. 344. 348. 352. 357. 361. 365. 370. 374. 379. 383. 388. 392. 397. 402. 407. 412. 417. 422. 427. 432. 437. 442. 448. 453. 459. 464. 470. 475. 481. 487. 493. 499. 505. 511. 517. 523. 530. 536. 542. 549. 556. 562. 569. 576. 583. 590. 597. 604. 612. 619. 626. 634. 642. 649. 657. 665. 673. 681. 690. 698. 706. 715. 723. 732. 741. 750. 759. 768. 777. 787. 796. 806. 816. 825. 835. 845. 856. 866. 876. 887. 898. 909. 920. 931. 942. 953. 965. 976. 988. } For E96, take the first element of the list and every second element, counting from the second; For E48, take the first element of the list and every fourth element, counting from the second... and so on. For series with two significant digits, the values should be rounded accordingly. I haven’t checked these, though. Regards, Gerson. |
|||
09-26-2017, 06:20 PM
(This post was last modified: 09-26-2017 06:21 PM by Dieter.)
Post: #32
|
|||
|
|||
RE: How do I learn RPL and solve this problem with it?
(09-26-2017 01:02 PM)David Hayden Wrote: I'd solve it like so: Great, finally a possible method that is better than "brute force". ;-) I tried a similar, but somewhat different approach. Here is how it works: Let T be the target resistance. Now do the following for all resistors > T and ≤ 2T:
Instead of quitting as soon as a combination within the allowed tolerance is found you can also run through all possible R1 (i.e. all resistors > T and ≤ 2T) and return the combination with the overall lowest deviation. But due to the individual tolerances of the two resistors this may not make much sense. On the other hand this returns the best possible combination even if it is not within tolerance. Here is an example: Try to find a combination for a target resistance of T = 350 Ω The first larger R1 in the E12 series is 390 Ω R2 = 350*390 / (390–350) = 3412,5 Ω So R2a = 3300 Ω and R2b = 3900 Ω 390*3300 / (390+3300) = 348,78 Ω which is T – 0,35% 390*3900 / (390+3900) = 354,55 Ω which is T + 1,30% The first value (3300 Ω) is within tolerance, so we already got a solution. Otherwise repeat these steps with R1 = 470, 560 and 680 Ω. Higher R1 values are not required, as 820 Ω already is > 2*350 Ω. This way a combination of two parallel resistors can be found. Here the best result was 348,78 Ω. In a final step, the gap to 350 Ω can be closed with another 1,2 Ω resistor in series. But since we are already within the tolerance of the individual resistors this is not really required. What do you think? Dieter |
|||
09-26-2017, 06:37 PM
(This post was last modified: 09-26-2017 06:41 PM by Claudio L..)
Post: #33
|
|||
|
|||
RE: How do I learn RPL and solve this problem with it?
(09-26-2017 02:55 PM)pier4r Wrote: I meant: the list of resistors (that are 96) is good to have in a precomputed form. Here's an idea for you: just have a list of the 12 basic ones, counting from 1.0, 1.2,1.5... You can always split a number with MANT and XPON. Since MANT gives you the mantissa 1.0 < x < 10.0 it works perfect. All we need to add is a 10 at the end of the list, and we are guaranteed the mantissa falls within the list. Then at the end we can multiply back by the XPON and there you go, or you can multiply the list by the XPON first, and work with the whole number, your choice. EDIT: Just to clarify, not to multiply directly by the XPON, but by the ALOG of the XPON. |
|||
09-26-2017, 06:46 PM
Post: #34
|
|||
|
|||
RE: How do I learn RPL and solve this problem with it?
Here's a program for the HP Prime using some ideas from Claudio to speed it up (for me PPL is much easier than RPL for writing quick programs such as this one) :
Code: Suffix(n) RES(523000) returns: 560K || 8.2M = 524.2K (0.23) RES(117) returns: 120 || 4.7K = 117.01 (0.01) RES(28) returns: 56 || 56 = 28 (0) Note: the special character that may not be rendered correctly is the small E for EEX |
|||
09-26-2017, 06:57 PM
Post: #35
|
|||
|
|||
RE: How do I learn RPL and solve this problem with it?
(09-26-2017 06:37 PM)Claudio L. Wrote: Here's an idea for you: just have a list of the 12 basic ones, counting from 1.0, 1.2,1.5... First: thanks for sharing. Second: for practical purposes (optimization comes after correct resolution) is it important? I mean if the list would be 200 or 2000 elements, I would find your tip needed due to memory constraints, but 96 elements are not that much even for userRPL I'd say (if they are precomputed). Or do I miss something? Wikis are great, Contribute :) |
|||
09-26-2017, 07:01 PM
(This post was last modified: 09-26-2017 08:37 PM by Dieter.)
Post: #36
|
|||
|
|||
RE: How do I learn RPL and solve this problem with it?
(09-26-2017 04:37 PM)Gerson W. Barbosa Wrote: Great insight! I know AWG wire diameters follow a geometric progression, but I wasn’t aware of this happening in resistor series. Unfortunately the actual resistor values are sometimes rounded up, sometimes down. But there is a way to calculate the nominal values of the E12 series. Here is a code snippet in VBA: Code: Function R(i) Enter an integer i and R(i) returns the i-th value of the E12 series, starting at 1 Ω. 0 => 1 1 => 1,2 2 => 1,5 3 => 1,8 ... 10 => 6,8 11 => 8,2 12 => 10 13 => 12 14 => 15 ... 53 => 27000 54 => 33000 ... Dieter Edited to correct an error in the program code |
|||
09-26-2017, 08:22 PM
Post: #37
|
|||
|
|||
RE: How do I learn RPL and solve this problem with it?
(09-26-2017 06:57 PM)pier4r Wrote: First: thanks for sharing. Nope, not missing anything. Just that I didn't see that as an optimization, my head sees it more as: argument reduction / algorithm / output. And my suggestion was in the argument reduction category, so I suggested it first, that's all. |
|||
09-26-2017, 08:25 PM
Post: #38
|
|||
|
|||
RE: How do I learn RPL and solve this problem with it?
(09-26-2017 07:01 PM)Dieter Wrote: Unfortunately the actual resistor values are sometimes rounded up, sometimes down. But there is a way to calculate the nominal values of the E12 series. Here is a code snippet in VBA: b=Round(b,1) doesn't seem right, as b is undefined? |
|||
09-26-2017, 08:36 PM
(This post was last modified: 09-26-2017 08:40 PM by Dieter.)
Post: #39
|
|||
|
|||
RE: How do I learn RPL and solve this problem with it? | |||
09-26-2017, 10:20 PM
(This post was last modified: 09-26-2017 10:21 PM by pier4r.)
Post: #40
|
|||
|
|||
RE: How do I learn RPL and solve this problem with it?
So still a greedy algorithm but a bit better than "compute all" Quite quick on the 50g.
Code:
note that serial will return positive percentage difference, parallel negative ones (because the inverted value is always bigger than the given one). Since it is greedy, I found at least some counterexample to the question "does it found always the best solution?" for example with 28, the serial solution is ok the parallel one is off. Anyway I learned that better to proceed by increasing improvements rather than being stuck. Wikis are great, Contribute :) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)