The Museum of HP Calculators

HP Forum Archive 09

 HP 42s solver questionMessage #1 Posted by Mike on 25 Nov 2002, 5:43 a.m. I have a simple program for the 42s that uses the solver to work out the value for the diameter of an object or area depending on what the user chooses (see below). What I would like to know, is there a way to also include the circumference while using the solver. For example if 7.3 was chosen for the "Dia" then if you pressed the key corresponding to "Area" it would work out 41.85 or if you pressed the key corresponding to "Circ" you would get 22.93. I'm not sure if this can be done but would be greatful if someone out there can help. Thanks Mike {41-Byte Prgm} LBL "Dia" MVAR "Dia" MVAR "Area" RCL "Dia" x2 PI X 4 / RCL- "Area" END

 Re: HP 42s solver questionMessage #2 Posted by Tom Sherman on 25 Nov 2002, 10:02 a.m.,in response to message #1 by Mike Hi Mike, From your numerical examples, and from the appearance of PI in the solver expression, it appears that "object" refers specifically to spheres. Revisions are needed both in the calculation of area, and in the program listing, since area = PI x d^2, and the result for your calculation of area should be 167.42 rather than 41.85. There is a confusion here of diameter and radius -- you are not the first, I do it all the time! But for the interesting question of whether there is any way to incorporate diameter, area, and circumference in one solver program: I don't think so. I believe you would need two separate expressions for the solver to solve. And how about the volume as well? This is one of those cases where a BASIC program would serve much better. Greetings from the coast of Maine, Tom

 Whoops! Sorry!!Message #3 Posted by Tom Sherman on 25 Nov 2002, 10:12 a.m.,in response to message #2 by Tom Sherman Mike, Forgive me. Your "object" is a circle, I guess, rather than a sphere. So your calculation is correct. Ignore all my rubbish except for the last paragraph. Tom

 A second lookMessage #4 Posted by Tom Sherman (again) on 25 Nov 2002, 1:06 p.m.,in response to message #3 by Tom Sherman If we wanted to write for the solver a single expression involving the three variables: diameter, area, and circumference (of a circle), we could do so. One example would be: ((PI*DIAM^2)/2)-AREA-((CIRC^2)/(4*PI))=0 which in effect says that twice the area minus the area minus the area equals nothing The problem is that because we have three variables in one expression, the solver will have to be given two of them in order to work. That would mean that if we started, for example, with the diameter, we would have to calculate the area separately to enable the solver to give us the circumference, or calculate the circumference separately in order to get the area.

 Re: A second lookMessage #5 Posted by r. d. bärtschiger. on 25 Nov 2002, 1:21 p.m.,in response to message #4 by Tom Sherman (again) A question: Isn't the area of a circle; 'Pi * r^2' not 'Pi * d^2' ? and Cicumference 'Pi * d' ? rdb.

 Re: A second lookMessage #6 Posted by Tom Sherman on 25 Nov 2002, 2:08 p.m.,in response to message #5 by r. d. bärtschiger. Yes, my expression is confusing (unorthodox), but I think it is OK -- but goodness knows, I am capable of messing this up forever! The first term represents twice the area, expressed in terms of the diameter. The area is (PI*d^2)/4 (or PI*r^2), so twice the area is PI*d^2/2. The second term represents the area in terms of the area -- that one is difficult! The third term represents the area in terms of the circumference. Since the circumference is PI*d, the square of the circumference is (PI^2)*d^2, which needs to be divided by 4*PI to give the area -- which again is (PI*d^2)/4. So then if we take the first term and subtract the other two we get zero. Or is it the sound and the fury signifying nothing? Sorry about all this! Tom

 Re: HP 42s solver questionMessage #7 Posted by Mike on 26 Nov 2002, 4:07 p.m.,in response to message #6 by Tom Sherman Thanks for your replies Tom, I will play around with your example.

 A BASIC program for the circleMessage #8 Posted by Tom Sherman on 26 Nov 2002, 5:57 p.m.,in response to message #7 by Mike Mike, Don't play around with it too much! The expression is a curiosity, but totally impractical. Ordinarily, if we know any one of the three features of a circle -- diameter, area, circumference -- we can directly calculate the other two. That is, if we have one we can get two. But with my expression put in the solver, we need two to get one! Not much of a bargain. Much better would be a simple BASIC program. The following is written for an HP-71B: 10 DESTROY ALL @ FIX 2 @ DELAY 2 20 DISP "DIAM=1,AREA=2,CIRC=3" 30 DELAY 8 40 INPUT "START WITH 1,2,or 3?";N 50 IF N>1 THEN 100 60 INPUT "DIAMETER =";D 70 DISP "AREA =";PI*D*D/4 80 DISP "CIRCUMFERENCE =";PI*D 90 GOTO 200 100 IF N>2 THEN 160 110 INPUT "AREA =";A 120 D=SQR(4*A/PI) 130 DISP "DIAMETER =";D 140 DISP "CIRCUMFERENCE =";PI*D 150 GOTO 200 160 INPUT "CIRCUMFERENCE =";C 170 D=C/PI 180 DISP "DIAMETER =";D 190 DISP "AREA =";PI*D*D/4 200 END Tom

 Re: A BASIC program for the circleMessage #9 Posted by Mike on 27 Nov 2002, 3:50 p.m.,in response to message #8 by Tom Sherman Thanks Tom, I also have the hp71b so I will have a play with that as well and see if I can program that. I haven't used it before so for a bit of fun I will try to enter your program. Thanks Mike

 Re: HP 42s solver questionMessage #10 Posted by Werner Huysegoms on 28 Nov 2002, 3:18 a.m.,in response to message #1 by Mike Two ways to do it: 1. write the equation like ABS(Area - Dia^2*PI/4) + ABS(Circ - Dia*PI) = 0 It works with the solver, but you'll find an extremum of course 2. use the name of the variable you're solving for: (how do I get this to show as I typed it instead of all in a row?) LBL "Dia" MVAR "Dia" MVAR "Area" MVAR "Circ" ASTO ST X "Area" ASTO ST Y X=Y? GTO 00 CLA ARCL ST X RCL "Dia" PI * RCL "Circ" - RTN LBL 00 RCL "Dia" X^2 PI * 4 / RCL "Area" - RTN I think the Alpha-register must remain untouched, hence the CLA ARCL ST X Werner Huysegoms

 Re: HP 42s solver questionMessage #11 Posted by Randy Sloyer(US) on 28 Nov 2002, 8:00 a.m.,in response to message #10 by Werner Huysegoms Werner: A very elegant solution. I worked on this for a few hours the other night and had given up on using solver for this. I never thought of having two solver programs within one. At least it got me paging through my new copy of the 42S programming guide (Thanks Iqbal!), so it was time well spent. I've made two insignificant changes (the RCL- )to the program and added the line numbers for ease of entry. This was formatted using a {pre /pre} block around the code listing. More options can be found here: http://www.hpmuseum.org/artfmt.htm ```00 {72 Byte-Prgm} 01 LBL "Dia" 02 MVAR "Dia" 03 MVAR "Area" 04 MVAR "Circ" 05 ASTO ST X 06 "Area" 07 ASTO ST Y 08 X=Y? 09 GTO 00 10 CLA 11 ARCL ST X 12 RCL "Dia" 13 PI 14 * 15 RCL- "Circ" 16 RTN 17 LBL 00 18 RCL "Dia" 19 X^2 20 PI 21 * 22 4 23 / 24 RCL- "Area" 25 RTN 26 END ```

 Re: HP 42s solver questionMessage #12 Posted by Mike on 28 Nov 2002, 4:23 p.m.,in response to message #11 by Randy Sloyer(US) Thanks you Randy and Werner, I tried your programs and they both seemed work correctly at first but only when you enter the "Dia" first, if you enter the others (area or circ)first it doesn't seem to calculate the correct result. I will try to understand how the program works and see why it is happening. Thanks for your efforts. Mike

Go back to the main exhibit hall