▼
Posts: 408
Threads: 45
Joined: Oct 2007
I wonder why HP choose to introduce difficult examples in RPN programming? for example, the HP30b modules have these examples:
1. calculating digits of PI
2. finding prime factors of an integer
3. base conversions for bases 210
http://h10025.www1.hp.com/ewfrf/wc/document?docname=c02047259&tmp_task=useCategory&lc=en&dlc=en&cc=us&lang=en&product=4031712
why can't they use examples like celcius to fahrenheit or solving quadratic equations like in the earlier HP 41C manuals?
I am still at a loss programming the new HP calculators from HP 35S onwards.
▼
Posts: 2,448
Threads: 90
Joined: Jul 2005
35s really is mostly the same as the 41C, to me. The odd parts are the new aspects with gotos that don't fit with the 32s paradigm. But it is still fundamentally the same as a 41, no?
Why not "simple" examples? Well, the two you gave are builtin functions, so that wouldn't be particularly useful, would it? May most of the "simple stuff" is already taken up with builtins!
I think the base conversion program is very useful for learning the programming.
Posts: 1,392
Threads: 142
Joined: Jun 2007
I think the idea was just to include some examples that most folks could relate to, so that they could see how programming is done on this machine, because it is somewhat different than "standard RPN" as many of us know it.
Here is a list of some "gotcha's" that you probably need to know about the 30b in order to program it effectively. Once you get used to some of its weird habits, I think you will like it, especially its speed.
The prime factor program shown is not the fastest in the world, but it is simple. Any regular member of this forum who knows RPN should be able to write a quadratic equation solver with little effort, especially since it won't need any conditional statements, typically. The 30b conditionals are a bit tricky until you understand how they work.
Posts: 1,545
Threads: 168
Joined: Jul 2005
Probably because there are examples of simpler programs elsewhere.
Examples of assigning programs to keys.
Examples of using HP solve.
etc.
then again, I'm certain that if the modules ONLY had the quadratic equation and F>C and C>F, more people here would have complained that the examples were too simple.
So, here you go. RPN mode assumed.
C>F... key celsius temperature, press = = while in the program catalog to execute.
LBL 0
9
x
5
/
3
2
+
R/S
F>C...key fahrenheit temperature, press = = while in the program catalog to execute.
LBL 1
3
2

5
x
9
/
R/S
For a quadratic, I would use the solver, not a program.
The learning module for using HP Solve shows several examples of how to do this.
HP Solve module
Example 1: Finding the roots of y = (x2)^2  1
Example 2: Finding the roots of y = (x2)^2 + 1
I can't help the typos in this web document.
Hope these help.
Edited: 31 July 2010, 11:53 a.m.
▼
Posts: 1,392
Threads: 142
Joined: Jun 2007
Quote: For a quadratic, I would use the solver, not a program.
On the 30b, to use the solver you're going to have to write a program anyhow, and if I'm going to write a program for this problem I'll implement the quadratic formula which will give me both roots without having to "guess." That's the one thing I've always disliked about the HP solver, it makes you guess in order to get both roots, and if you guess, you probably already know the answer!
▼
Posts: 1,545
Threads: 168
Joined: Jul 2005
True, true.
But if someone is unsure about programming enough that they really need examples for converting F>C and C>F, then a short program in the solver for X^24X+4 is probably easier to type in and run than a longer one to give both roots at once.
But, I do agree with your point, certainly. :)
▼
Posts: 1,392
Threads: 142
Joined: Jun 2007
Thanks, Gene. That's one thing I like about the NSpire, it's SOLVE function. Now, I know the NSpire is a CAS and the 30b is not, but if you type in SOLVE(x^2+5x+6=0,x) it comes back with x = 2 or 3. Now that's what a solver ought to do!
Posts: 1,792
Threads: 62
Joined: Jan 2005
Quote:
That's the one thing I've always disliked about the HP solver, it makes you guess in order to get both roots, and if you guess, you probably already know the answer!
I can't concur with that statement. The idea behind the 'guesses' is to bound the interval for the root of interest. The user may know the approximate value of that root, but requires automated numerical iteration in order to efficiently "home in" on it.
Also, periodic functions may have an infinite number of realvalued roots.
From your subsequent post:
Quote:
...if you type in SOLVE(x^2+5x+6=0,x) it comes back with x = 2 or 3. Now that's what a solver ought to do!
Sure, but that's a quadratic function with two exactlyspecified, easily calculated roots (which may or may not be realvalued). A solver can be programmed to find all roots of a polynomial function; the convenient "SOLVE POLYNOMIAL" screen of the HP48G series, as well as the PROOT function of the HP71B Math Pac, will do so.
 KS
Edited: 4 Aug 2010, 11:33 p.m. after one or more responses were posted
▼
Posts: 1,392
Threads: 142
Joined: Jun 2007
Karl, I guess we'll have to agree to disagree. Yeah, the user may have an idea of the value of the second root, but he may not also and will have to do more work with the solver to find it. I think the real value of the HP solver is finding solutions to firstdegree equations with multiple variables, where you know the values of all variables except one and it will calculate and tell you that one. And I like the approach used in machines like the 17bii where you just enter the equation (don't have to set it to 0) and provide values for the known variables and it tells you the unknown. I like that approach more than requring you to write a program, as in the 30b for example.
But, truth be told, I think the method I like best is doing it in my head, like completing the square or factoring or using the quadratic formula manually. I've read that doing mental things as you get older (I'll be 60 in a couple of weeks) keeps you from getting Alzheimer's disease, plus it's just fun!
▼
Posts: 1,253
Threads: 117
Joined: Nov 2005
Quote:
I've read that doing mental things as you get older keeps you from getting Alzheimer's disease, plus it's just fun!
I sure hope that's true  my ultimate antiAlzheimer trick is 41MCODE, highly recommended. :)
Posts: 1,792
Threads: 62
Joined: Jan 2005
Don 
Quote:
Karl, I guess we'll have to agree to disagree. Yeah, the user may have an idea of the value of the second root, but he may not also and will have to do more work with the solver to find it.
I took your sentiment of not liking the 'make a guess' requirement in more general terms, as opposed to pertaining specifically to quadratic solutions.
I still maintain, though, that the user ought to be able to deal adroitly with quadratics, even working them out manually in lieu of programming a solution. The best way for a calculator to return both/all solutions automatically, without the benefit of guesses entered by the user, is with a polynomialsolving function.
Oftentimes, one mathematical quadratic solution will have no practical use in a realworld problem.
Quote:
I think the real value of the HP solver is finding solutions to firstdegree equations with multiple variables, where you know the values of all variables except one and it will calculate and tell you that one.
They need not be 'first degree' equations; the multivariable equation can be of any form. RPNbased HP solvers will use two 'usersupplied' guesses from stack contents and the stored value of the 'solve' variable. I would assume that the stored value (if present) is the starting point for the HP17B/27S solver.
If the guesses are the same, the solver will decide in which direction to proceed. If the solver is to succeed, neither guess must cause a math error.
http://www.hpmuseum.org/cgisys/cgiwrap/hpmuseum/articles.cgi?read=556
 KS
Edited: 6 Aug 2010, 1:40 a.m. after one or more responses were posted
▼
Posts: 850
Threads: 10
Joined: Mar 2009
I think the problem is again what the older generation complains so much about  people want to just punch problems into computers and get answers, losing all inkling of whether the answer makes sense. This has been discussed so often on this forum. The same goes in this case where calculators can be programmed to give answers to simpler quadratics without guesses, but for more complex problems there can be a multitude of answers and you can be sure the calculator giving you definite solutions will give the ones you don't want. I think working with a calculator that forces you to guess even for the simple quadratics, teaches you to do it right for the more complex ones.
▼
Posts: 1,392
Threads: 142
Joined: Jun 2007
Quote: This has been discussed so often on this forum.
I think we can all agree with that!
Here's what I think. It's not the calculator's responsibility to make sure that the person pushing its buttons understands the answer it provides. That's probably somebody's responsibility, but not the machine's. If a solver application can find a solution without the buttonpusher providing a guess first, do it. Personally, I'd like the solver to do this for a quadratic equation: recognize that it's a quadratic, get the coefficients of x^2 and x and the constant term (a, b, and c), apply the quadratic formula, and return the two solutions (if there are two solutions) in x and y. Now, there may be a legitimate reason that the solver has not taken this approach in the past, so that's OK. But maybe it's time to update the solver (radical idea).
I teach my middle school students to find the solutions to quadratics by factoring, if possible, then completing the square, then applying the quadratic formula, and I think that's good because it makes them think (and work!). Once they leave school, they will probably never have to do such things again in their life (similar to boxandwhiskers plots, don't get me started on those), but the process of doing it now exercises their brains in ways that video games cannot.
▼
Posts: 1,792
Threads: 62
Joined: Jan 2005
Quote:
Personally, I'd like the solver to do this for a quadratic equation: recognize that it's a quadratic, get the coefficients of x^2 and x and the constant term (a, b, and c), apply the quadratic formula, and return the two solutions (if there are two solutions) in x and y.
This requires that the equation be entered in full detail. And, what if the terms had not been gathered  should the calc still be able to recognize it as a quadratic? Any sophisticated solution will entail CAS.
I still say that the ideal solution is a polynomial solver, like that of the HP48G and its descendants: Choose "Solve Polynomial" from the SOLVE menu, enter [1 5 6], hit "Solve", and read 2 and 3 as the answers. A PC might be a better tool if the problem is more complicated than that.
A quadraticequation problem came up at work recently. After failing for a short while at simply reckoning an operating point, I derived a quadratic expression, programmed it as an equation on the HP32SII, and quickly solved it numerically, knowing what a realistic answer would look like. (The other solution, which I computed manually, was indeed unrealistic  well outside the operating limits of the equipment. The HP32SII found that one, too, with suitable guesses steering it in that direction.)
 KS
Edited: 8 Aug 2010, 2:21 a.m. after one or more responses were posted
▼
Posts: 1,392
Threads: 142
Joined: Jun 2007
Yeah, trying to determine if a solver program represents a quadratic equation would be problematic, given all the possibilities and different coding styles of users. So I admit, that's a bad idea.
One thing I like about the SOLVE command on the TINspire is that it is general purpose. It solves simple equations, quadratic and higher order equations, and systems of equations (what we called simultaneous equations when I was in high school, I always wondered why they changed the name). And it doesn't require you to set the whole thing equal to zero.
solve (x12=30,x) yields x=42
solve (x^2+5x+6=0,x) yields x=2 and x=3
solve (x+y=11 and xy=3,x,y) yields x=4 and y=7
There is also a CSOLVE command for complex numbers, but I've never used it.
Edited: 7 Aug 2010, 3:01 a.m.
Posts: 2,247
Threads: 200
Joined: Jun 2005
Solving for the roots of polynomials (with real coefficients) using the LinBairstow algorithm requires no guesses for the roots. This algorithm will find all of real and complex roots of the polynomial. Unfortunately, when it comes to nonpolynomial functions, at least one guess for the root is required to tell, whatever algorithm being used, where to start looking.
Namir
▼
Posts: 735
Threads: 34
Joined: May 2007
Quote:
using the LinBairstow algorithm requires no guesses for the roots
However you need to give initial values (guesses) for the quadratic polynomial. Also Wikipedia states:
Quote:
As first quadratic polynomial one may choose the normalized polynomial formed from the leading three coefficients of f(x),
Is there a reason for that choice? In my experience it just doesn't matter much, what you chose.
For those interested I once wrote a program for the HP11C.
However the trick using L.R. to solve the linear equation might not always work with later HP models since n is checked to be positive.
My first encounter with this algorithm was with an article in PRISMA, the magazine of the former CCD. The program was written for the HP41C (of course) and I didn't understand a single thing, what was going on. It must have been around 1984. Unfortunately I've lost the copy of the article but maybe someone in this forum can still find it.
JeanMarc Baillard contributed a solution to the MoHPC HP41C Software Library:
Polynomials for the HP41
cf. g) Quadratic factors ( Bairstow's method )
Kind regards
Thomas
▼
Posts: 2,247
Threads: 200
Joined: Jun 2005
Thomas,
The implementation I use of LinBairstow internally provides the initial guesses for the quadratic coefficients. The caller to the LinBairstow subroutine needs not supply any initial guesses.
Thank you sooooo much for the HP11C listing your provided. I was looking for such an implementation that uses no memory registers. Good job!!
Also thanks to the link to Baillard's excellent 41C listings. I was thinking of writing a (new) Bairstow method. The listing is interesting/
Namir
Edited: 5 Aug 2010, 3:55 p.m.
▼
Posts: 735
Threads: 34
Joined: May 2007
The images in the Wikipediaarticle suggest that there are initial guesses that might lead to divergence for certain polynomials. Do you know how this is avoided in the implementation you use? Are there best initial guesses that can be easily computed from the coefficients as suggested? Do you know the reason for this suggestion?
My implementation of course uses some memory registers but I tried to use as few as possible. Otherwise you run out of memory for the program. IIRC it's possible to solve polynomials up to degree 7, probably even a little more if you sacrifice the quadratic solver program at LBL A.
It's nice you like the program.
▼
Posts: 2,247
Threads: 200
Joined: Jun 2005
I emailed you the listing of a VB SUB that implements the LinBairstow algorithm. The museum email server may have converted some characters. You can write me at nshammas{AT]aol[DOT].com if you want me to send you the entire Excel file.
Namir
▼
Posts: 735
Threads: 34
Joined: May 2007
From the listing you sent me:
' start the main LinBairstow iteration loop
' initialize the counter and guesses for the
' coefficients of quadratic factor:
'
' p(x) = x2 + alfa1 * x + beta1
'
alfa1 = 1
beta1 = 1
It appears the same initial values are used as in the example of my solution:
1 STO 7
STO 8
Remark: Please note the slight difference in the definition of the remainder polynomial:
Wikipedia:
cx + d
My solution:
R(x) = b1 ( x + p ) + b0
It turns out to make the algorithm more concise since there's no special case in calculating b0 (in my solution) as it would be for:
d = a0  v b0
Please note also the shift of indexes by 2 when comparing the quotient:
Q(x) = b_{n} x^{n2} + b_{n1} x^{n3} + ... + b_{4} x^{2} + b_{3} x + b_{2}
These kind of subtleties may have a considerable impact on the code.
