![]() |
[WP34s] New TVM-solver version - Printable Version +- HP Forums (https://archived.hpcalc.org/museumforum) +-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html) +--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html) +--- Thread: [WP34s] New TVM-solver version (/thread-236122.html) |
[WP34s] New TVM-solver version - fhub - 12-16-2012 Hi, I've made a new version of my TVM-solver: http://www.hpmuseum.org/guest/fhub/tvm.zip
This new version is now also able to find both results when calculating the interest rate 'I' (if 2 solutions exist).
Let me know if you discover any problems,
PS: Here's the thread where Dieter reported this problem (with 2 solutions for the interest rate) and posted a few examples:
Edited: 16 Dec 2012, 11:43 a.m.
Re: [WP34s] New TVM-solver version - Paul Dale - 12-16-2012 Is it still okay to include this new version as part of the 34S library in firmware? If so, I'll add it in.
Re: [WP34s] New TVM-solver version - fhub - 12-16-2012 Quote:Yes of course - if you don't worry about the 100 steps more. ;-) BTW, this new version has a bit different handling as the one currently included in the WP34s library. I made it from my later version which uses [A] as prefix key and then the 5 top-row keys [A]..[->] for the 5 financial variables. That's the way all usual financial calculators do it, and it's definitely more comfortable (and it displays the 5 keys in the alpha display). Franz
Edited: 16 Dec 2012, 12:07 p.m.
Re: [WP34s] New TVM-solver version - Walter B - 12-16-2012 Quote:Hope you documented it properly.
d;-)
Re: [WP34s] New TVM-solver version - fhub - 12-16-2012 Quote:Yes, as usual the doc is commented at the beginning of the file.
Franz
Re: [WP34s] New TVM-solver version - Walter B - 12-16-2012 Good boy!
d:-)
Re: [WP34s] New TVM-solver version - fhub - 12-16-2012 Quote:Well, to be really a 'good boy' I would have to write at least a 100+ pages PDF documentation (like your WP34s manual). But I'm just too lazy for it. ;-)
Franz
Re: [WP34s] New TVM-solver version - fhub - 12-16-2012 I forgot something: Since I have only the emulator of the WP34s I would be curious how long such a interest rate calculation for 2 solutions need on a real WP34s.
If anyone has loaded the new TVM version above in a real WP34s, then it would be nice to execute the following calculation: N=10Then solve for 'I' and stop the time until the solutions are displayed.
Thanks, Re: [WP34s] New TVM-solver version - Paul Dale - 12-16-2012 Built in the old respoistory as version 3335. The new respository (which we're being forced into using anyway soon) doesn't have build machine support yet.
Re: [WP34s] New TVM-solver version - fhub - 12-16-2012 Quote:A small problem: you've put the old manual (v2.2) into the current version.
Franz
Re: [WP34s] New TVM-solver version - Paul Dale - 12-16-2012 Nice catch. Looks like a problem with the build process and recent changes. Or something I did that was silly -- insomniac commits before 4am aren't sensible.
Re: [WP34s] New TVM-solver version - Marcus von Cube, Germany - 12-16-2012 I have yet to try your application on my 34S. My 27S fails on your example ("many or no solutions").
Re: [WP34s] New TVM-solver version - Marcus von Cube, Germany - 12-16-2012 There shouldn't be a manual in the bin directory in the repository. The current manual can be copied there locally under the name wp34s_manual.pdf to support the help menu of the emulator but the file shouldn't be committed.
I've deleted the stray copy in the repository.
Re: [WP34s] New TVM-solver version - fhub - 12-16-2012 Quote:Yes Marcus, I've tried this on every existing (financial) HP calculator (or rather on their emulations), and all of them returned this error message as result. But since Dieter said that such a behaviour won't be acceptable for a high-end calculator like the WP34s, I decided to finally solve this problem (although it never happens in reality). ;-)
Franz
Re: [WP34s] New TVM-solver version - Dieter - 12-16-2012 What a coincidence. Over the last days I tried the one or other alternative approach to the TVM problem, and basically it boils down to the same ideas. ;-) While I did not transfer your program to a physical 34s (honestly, I do not know how to do that, i.e. move a .wp34s file to a physical 34s' RAM), I can provide some results of two similar solutions.
BTW - did you also try some cases with 0 < n < 1? On this interval things are a bit different. Dieter
Edited: 16 Dec 2012, 5:18 p.m.
Re: [WP34s] New TVM-solver version - Dieter - 12-16-2012 Quote:Yes, that's the easy way to, err... "solve" this problem. #-) IMHO a decent solver should find out 1. whether no or two solutions exist, and 2. if there are two, what are their values.
Dieter
Re: [WP34s] New TVM-solver version - fhub - 12-16-2012 Quote:Well, no coincidence at all - of course I've improved my program only because you complained about not finding such double-solutions. And of course splitting the interval into 2 parts by searching for the minimum/maximum is the logical way to do it. ;-)
Your method of using an own Newton-solver is an alternative (and maybe indeed faster) method than calling the integrated rootsolver, but IMO it's not worth the troubles (i.e. the effort to write a well working code and the quite big size of such a code). Such problems with 2 solutions occur so rarely that I won't worry about waiting a few seconds for the results. Quote:Yes I know (I've even tried a few graphs with n<0), but I don't see any sense in decimal number for n at all, at least not when there are periodical payments (i.e. if PMT!=0).
Take the following example: So to handle also this case the TVM solver would need a HUGE enhancement, and that's something I would consider for a PC program but not for a tiny calculator like the WP34s. Ok, in the meantime I already know you a bit, so I'm quite sure that you'll certainly disagree with me again ... ;-) Franz
Edited: 16 Dec 2012, 5:40 p.m.
Re: [WP34s] New TVM-solver version - Dieter - 12-16-2012 It's late, so let me add just two remarks: Quote:It's actually less effort since this method does not rely on the position of an extremum - the whole process of finding its location can be omitted. Simply take two initial guesses derived from -1 and +infinity. In this case that's -30/100 and 30/50, i.e. -30 and +60%. Which is quite close to the actual solutions -28,4% and 58,2%.
Quote:I agree or disagree with opinions, not with persons. So don't take things too personally - it's just simple mathematics. ;-)
Dieter
Re: [WP34s] New TVM-solver version - fhub - 12-16-2012 Quote:Unfortunately not in all cases. For some values the special form of the TVM graph (at least for the TVM formula that I use) can put the 2nd guess far away from your initial value (on the opposite side of the min/max), so also your method is not foolproof. And if you check for such conditions, then it's not only a thing of coding the Newton formula. Franz
Edited: 17 Dec 2012, 6:05 a.m.
Re: [WP34s] New TVM-solver version - Marcus von Cube, Germany - 12-16-2012 Quote: Here it goes:
Re: [WP34s] New TVM-solver version - Paul Dale - 12-16-2012 I think Walter added it a short while back.
- Pauli
Re: [WP34s] New TVM-solver version - Paul Dale - 12-16-2012 Quote: I wouldn't quite call it that or anyone would be writing robust TVM solvers easily. The fact that Professor Willian Kahan's carefully constructed algorithms for the 12C fail in some cases, is to me at least, an indication that this is not even a remotely simple problem to solve correctly. I would even go as far as to put a part of the 12c amazing longevity down to the simple fact that it was producing better answers than the competition when introduced (and still today I suspect).
Re: [WP34s] New TVM-solver version - Walter B - 12-17-2012 Two remarks AFAIK: 0. Make sure the program you want to transfer is part of the library on the emulator. See the assembler manual for this step. 3. should read: Connect the computer and your WP 34S with a proper cable (see p.147).
d:-)
Re: [WP34s] New TVM-solver version - Walter B - 12-17-2012 Agree (except on "mustn't").
d;-)
Re: [WP34s] New TVM-solver version - Dieter - 12-17-2012 Quote:Please give an example. Quote:Things only have to be foolproof if used by fools. 8-)
Dieter
Re: [WP34s] New TVM-solver version - Dieter - 12-17-2012 Quote:What's the name of that file? Quote:I assume these are the steps to get a program from the emulator to a physical 34s. Now, all I have is a file named tvm.wp34s - how do I get that to a (physical) 34s? I am able to assemble this file to a .dat file, but I am not sure about how to move this to the emulator (library? RAM?) or "the real thing".
Dieter
Re: [WP34s] New TVM-solver version - Walter B - 12-17-2012
Quote:See p. 166 of the v3.1 manual.
d:-)
Re: [WP34s] New TVM-solver version - Marcus von Cube, Germany - 12-19-2012 wp34s.ini. Sorry for not mentioning it.
If you look at the SVN repository, you'll see a .cmd file in the top directory that I'm using to build the default library. Pauli has already done that so you can just take the file wp34s.lib in the library directory (latest build in the old repository).
Re: [WP34s] New TVM-solver version - fhub - 12-19-2012 Quote:Old repository? Is there a new one? Could we have the link? ;-)
Franz
Re: [WP34s] New TVM-solver version - Paul Dale - 12-19-2012 Main source forge page, click on Code tab. Instructions follow. This isn't something we really wanted to do, but SF is forcing a change over in the coming months so I got in early to give us time to iron out issues.
Re: [WP34s] New TVM-solver version - fhub - 12-19-2012 Quote:Thanks, found it. You're right, looks a bit confusing when used to the old SVN. But I even found your new WP43s site, although it's still in a prenatal state ... ;-)
Franz
Re: [WP34s] New TVM-solver version - Walter B - 12-20-2012 Quote:Almost. The file is called wp34s-lib.dat and ist found using that link.
d:-)
Re: [WP34s] New TVM-solver version - Marcus von Cube, Germany - 12-20-2012 Quote:
Sorry for mixing it up again. I must have been a bit overworked when I tried to answer the question.
Re: [WP34s] New TVM-solver version - fhub - 12-21-2012 New version 3 of the TVM solver:
Now solving for 'I' also works for negative periods N<0 (whatever this is good for ;-)). Franz
Edited: 26 Dec 2012, 5:48 a.m. after one or more responses were posted
Re: [WP34s] New TVM-solver version - Paul Dale - 12-21-2012 I've committed the new code but haven't built anything.
Re: [WP34s] New TVM-solver version - fhub - 12-21-2012 Isn't it already Dec 22 in Australia?
Franz
Re: [WP34s] New TVM-solver version - Paul Dale - 12-21-2012 It is 23:18 here on the 21st. Other parts of Australia have reached the 22nd and some parts are further behind still.
Re: [WP34s] New TVM-solver version - fhub - 12-21-2012 Quote:Aaah, then enjoy your last minutes! :-)
Franz
Re: [WP34s] New TVM-solver version - Walter B - 12-21-2012 Franz, you mixed it up: that was a prophecy for Austria, not Australia (to our friends in GOC: yes, there is a difference, even a pretty large one)!
d:-)
Re: [WP34s] New TVM-solver version - Dieter - 12-25-2012 I the meantime I managed to transfer the new TVM solver to my hardware 34s where it now replaces the former version in the library. So I tried the following case: n = 5The 34s requires nine seconds to return the two solutions: I1 = -9,321I observed two problems: First, the iteration sometimes does not seem to terminate. This possibly is not a problem in the TVM routine but either in the internal solver or maybe even the 34s firmware itself. After starting the calculation with [A] [B] the RCL indicator in the display starts flashing very slowly in irregular intervals: the indicator may come on for a second or two, then it disappears for another two seconds, comes back again, etc. In many cases this evetually led to a RESET message. After R/S the program then usually finishes within a few seconds (with the RCL indicator flashing as usual at about 1 Hz), as if nothing had happened at all. Pauli, Marcus? And finally, after pressing [B] the iteration starts, but the display continues to show its N I PV PMT FV message. Except the flashing RCL indicator there is no visible feedback to the user, telling him that a calculation is in progress. I would like to see something like "Solving..." while the interest rate is being calculated. BTW: In the current version, the [A] key is used to enter values as well as to start their calculation. What about two keys, say [A] and [B] - one for storing values and the other to have them calculated? Like a [SET] and [COMPUTE] button, similar to what is found on other brand calculators. This way we would also get rid of the cumbersome ENTRY? test and the one or other additional [R/S] to clear the entry flag.
Dieter
Re: [WP34s] New TVM-solver version - Dieter - 12-25-2012 Quote:The new version runs for about ten seconds before both solutions are returned. However, I also observed a problem that may not be related to your code (see my other post a few minutes earlier). In this case the calculation starts with the RCL indicator continuously on, after about eight seconds RESET appears, and after that [R/S] returns the two solutions in another eight or nine seconds.
Dieter
Re: [WP34s] New TVM-solver version - Marcus von Cube, Germany - 12-25-2012 I fear I've broken your hardware. :-( I'll have to test with one of my devices if the "reset" phenomenon is the same.
Re: [WP34s] New TVM-solver version - fhub - 12-25-2012 Hi Dieter! Quote:Ooops, that's indeed a bit long! :-( But this only if there are 2 solutions, for usual TVM problems with 1 solution the time should be less than 3 seconds, because only 1 instead of 3 SLV calls are needed, and I would say that this is acceptable. Quote:Well, I'm absolutely sure that it's not the fault of my program and I'm quite sure that it's also not the SLV routine. I'm calling SLV only when the interval of the 2 initial guesses has different signs on both ends, so the solver should always find a solution. And in fact in 99.9% of all examples I've tried the solver returns this solution - only in very rare cases (e.g. for interest rates < -99.9%) sometimes it doesn't find a solution. The reason is that for such unrealistic interest values the TVM expression may have really huge values (e.g. 10^30), and then SLV fails. But such I-values are clearly out of the valid range. I rather guess there's a problem with your firmware build, but let's wait what Marcus gets on his WP34s. Quote:Yes, that may indeed be a good idea. The problem is that I only have the emulator, so solving for 'I' is done in a fraction of a second and for me this message disappears immediately
What would you prefer, just delete this 'N I PV PMT FV' display or really showing 'Solving..' (which would require more bytes of course)? Quote:That's an idea which I won't like very much. AFAIK all financial HP calculators work exactly this way, i.e. if you've entered a value before pressing those keys the value is stored, else it is calculated. I would say that's the most simple method, and shouldn't the WP34s be as compatible as possible to all other HP calculators? BTW, if you've entered anything previously and then want to calculate any of the 5 TVM values, there's no need to press [R/S] before - you can just press [A][?] twice: the 1st press stores the value, but the 2nd press calculates it. Franz
Edited: 25 Dec 2012, 4:17 p.m.
Re: [WP34s] New TVM-solver version - fhub - 12-26-2012 I've now implemented this 'Solving...' message when the SLV iteration is used to calculate the interest rate 'I'.
Additionally I've found a small error in one of my formulas (derivative of TVM for i=0), so of course also this bug (although it would probably never occur) is fixed in the new version:
Franz
|