I wanted to find the minimum of x^1/2.
I tried Fill sqrt y^x. RTN. Using solve the on board f'(x) for .1 to 1, I get a domain error. On the HP 35s, the Dieter program works like a champ. What am I doing wrong?
HP 34s solve f'(x)=0
|
|
« Next Oldest | Next Newest »
|
▼
Post: #2
10-05-2013, 03:11 PM
I wanted to find the minimum of x^1/2. I tried Fill sqrt y^x. RTN. Using solve the on board f'(x) for .1 to 1, I get a domain error. On the HP 35s, the Dieter program works like a champ. What am I doing wrong? ▼
Post: #4
10-06-2013, 04:22 AM
The problem here is f'(x) samples from the function at a number of points around the given x value. By default the step size is 0.1 which means you end up with -.1-.1, which the 34S cannot deal with. Define the [delta]X global label to set the step size yourself. See the manual entry for f'(x) for details. The [delta]X label isn't case sensitive.
▼
Post: #5
10-06-2013, 08:53 AM
...or you could put a test in your program for negative / zero values and return "1" when they are detected. This will slow things down slightly, but the WP-34S is fast! Nigel (UK)
Post: #6
10-06-2013, 12:27 PM
What puzzles me is that I use dx=.029....this seems to give better results on some problems than the default of .1 or some small dx such as 1E-06. Still, using dx=.029, and using a tight interval for solve (1.2 to 1.4) for this function where f'(x) is real for x>0, and should equal 0 for x~1.353, why should this produce the domain error? I clearly don't know how f'(x) is approximated on the 34s and/or how this works using solve to find f'(x)=0
▼
Post: #7
10-06-2013, 04:44 PM
Quote:For f(x) = xsqrt(x) the first derivative is 1/2 xsqrt(x)-1/2 (2 + ln x). Which is zero for x = e-2 = 0,135335. And that's what my 35s program returns as well: Y001 LBL Y Dieter ▼
Post: #8
10-06-2013, 05:17 PM
I gave your program credit in my 1st post...indeed it worked great. I modified the program slightly so that I can then execute f(x) at that point, and have both values show simultaneously on the HP 35s 2 line display. Still puzzled by the 34s since my dx is small (.029) and f'(x) is real all the way down to zero ▼
Post: #9
10-06-2013, 05:49 PM
The 34S uses a ten point numerical derivative if it can. This means it will go five times .029 = .145 either side of the value the solver supplies. This is more than enough to bring the evaluation point negative on its own, however the solver will also attempt to bracket the root pushing it even further negative. You could try setting flag D to allow not number and infinite results. The derivative code should fall back to lower order numerical derivatives if the function returns NaNs. I'm not sure what the solver will do, but there is some attempt to deal with things in there. The source code for the solver and the derivative routines are in the trunk/xrom directory, if you want to investigate the internal behaviour further.
Post: #10
10-07-2013, 03:03 PM
Quote:Thank you very much. However, I basically wanted to point out that the local minimum is not located at x = 1,353 or somewhere between 1,3 and 1,4, as you wrote. Actually it is at x = 0,1353.
Quote:The 34s f'(x) command evaluates the user function at numerous points around x. Pauli mentioned an interval of x +/- 5 dx. With dx as large as 0,03 this means you will get significantly below zero.
I tried your function xsqrt(x) in the following way on the 34s. Two points are essential:
0,1 ENTER 1 SLV "DER"This agrees in 10 digits with the true result. Addendum: unlike simple implementations, the 34s multi-point derivative seems to handle large dx values very well. In the above code, replace SDR 05 with SDR 02, and RDP 09 may become RDP 12. For the same initial guesses, the solver should now return a result with 14 valid decimals. Dieter
Edited: 8 Oct 2013, 4:20 p.m. |