▼
Posts: 376
Threads: 35
Joined: Jul 2007
I know on HP 48gx, it fairly easy to find derivative of an equation where the slope equal 0 and determine if it the low point of curve or high point of curve. I know how to do manually, with chain rule, set to zero and solve, but is there easy way to have 35s do this?
▼
Posts: 26
Threads: 9
Joined: Aug 2007
Doesn't the SOLVE set a flag when it hits a minimum/maximum instead of a root?
▼
Posts: 376
Threads: 35
Joined: Jul 2007
I don't know. Are you saying, let it iterate until it hit zero?
Posts: 26
Threads: 9
Joined: Aug 2007
Try solving for the root of, e.g. (x2)^2+1:
LBL F
RCL X
2

x^2
1+
RTN
then
FN=F
SOLVE X
will give you "NO ROOT FOUND", but a 2 in the display.
Of course, as soon as your function has a root, this method will not work.
You probably could do (limited) symbolic derivatives using RPN, using the indirect array, since differentiating in RPN is easier than in ALG:
e.g. x^2
X x^2
can be diff'd by replacing x^2 by 2 *.
Addition and subtraction just stays the same (+ and ).
Product rule is a bit more advanced: You have to replace
X Y *
by
X Y' * X' Y * +
and have to evaluate X', Y' by recursion.
All what's left is to find a suitable representation of the symbols as numbers in the indirect registers, but that's a triviality :)
Cheers, Peter.
Edited: 23 Aug 2007, 5:24 p.m.
Posts: 1,545
Threads: 168
Joined: Jul 2005
Yes, but unfortunately, you have to put the derivative formula in the solver and solve for zero. :)
▼
Posts: 376
Threads: 35
Joined: Jul 2007
So if dy/dx = 3x^3+4.2x^2  15, find 9x^2+8.4x and then set to 0 or 9x^2+8.4x = 0, and just enter that in solver? That easy enough...duh :) Been long week I guess.
What if you had a complex equation that not as simple as one above though, is there easy way to differentiate it and solve? Something like:
dy/dx = (sqrt(43x^3/52x+5)*654.2^254/458)/sqrt(675^2+98)
▼
Posts: 1,545
Threads: 168
Joined: Jul 2005
If you can express the derivative as an equation on the 35s, then you can solve for a zero.
▼
Posts: 376
Threads: 35
Joined: Jul 2007
No, I think you nem understand what I asking. Let me think about how to explain this better.
Only reason that we set to zero, is to find out if it minimum point or maximum point on curve. We must find 1st derivative first. Solving for zero is very easy, and I understand, but sometime finding first derivative is not so easy. Is there way that 35s can do that? Such as if I type in 3x^3+4.2x^2  15 it find 9x^2+8.4x is first derivative. Or if I type in (sqrt(43x^3/52x+5)*654.2^254/458)/sqrt(675^2+98) it tell me what 1st derivative is. It should return a formula, not a value. I guess I asking if it can differentiate.
▼
Posts: 1,545
Threads: 168
Joined: Jul 2005
It cannot symbolically differentiate like you suggest. The graphing models with a CAS can, but not the 35s.
▼
Posts: 376
Threads: 35
Joined: Jul 2007
That not answer I was wish for my friend. :( Well, I have 48gx that can do it I guess, but I rather leave that calculator at home. I wonder how hard it would be to write program to differentiate? It would have to ask for variable you wish to differentiate. Hmmm, I must think about. I have feeling though it would not be easy to symbolically manipulate equation.
I wonder if our friend Valentin could do? He probably say I eat too much paprika and it going to my head and rusting brain cells.
▼
Posts: 776
Threads: 25
Joined: Jun 2007
You can always calculate the derivative numerically:
evaluate [f(x+dx)  f(x)]/dx
You may have to play with the size of dx, and there may be unstable regions, of course  just as we learned in Calc I .
▼
Posts: 376
Threads: 35
Joined: Jul 2007
Yes, but how would you do that on the 35s? I do not have my manual with me (Gene, when we going to have PDF of manual?) Honestly though, I prefer symbolic result as it show me more.
▼
Posts: 217
Threads: 21
Joined: Aug 2007
Quote:
Yes, but how would you do that on the 35s? I do not have my manual with me (Gene, when we going to have PDF of manual?) Honestly though, I prefer symbolic result as it show me more.
Then the HP 35s isn't the calculator you want. The 35s is purely numeric.
Stefan
Posts: 217
Threads: 21
Joined: Aug 2007
You can use this in conjunction with the solver then, solving a program instead of an equation. For example, to find the minimum/maximum of 3*x^2+2*x+1.
F001 LBL F
F002 EQN 3*X^2+2*X+1
F003 RTN
D001 LBL D
D002 RCL D
D003 STO+ X
D004 XEQ F001
D005 x<>y
D006 STO X
D007 x<>y
D008 XEQ F
D009 
D010 RCL/ D
D011 RTN
Program F implements the function you want to find the minimum/maximum of.
Program D computes F'(x) using the approximation (F(x+dx)F(x))/dx, where you prespecify dx in register D.
Now use SOLVE:
FN= D
0.001
STO D
SOLVE X
This yields X=0.3338.
You can now easily determine F(X) by just pressing:
XEQ F
Which yields F(X) is 0.6667.
Checking this symbolically, the derivative is 6x + 2, which is 0 for x=1/3.
The difference in the answer is due to the approximation to the derivative. Using a smaller value in D will result in a more precise answer.
Stefan
▼
Posts: 776
Threads: 25
Joined: Jun 2007
Very slick. Thanks for implementing my suggestion!
Posts: 376
Threads: 35
Joined: Jul 2007
That work to show you values, but in business you need to see the curve (or understand it). This used many time to solve for profit maximization of cost minimization curve. Your example yes tell me where point is (0.3338), and it also tell me that it is cost minimization curve from value 0.6667 which positive which mean that curve is increasing after zero.
I guess that could work if you need value. Okay, I was just hoping it could show symbolically some how too.
What I don't understand though is your formula. Any you can explain steps in D program.
▼
Posts: 26
Threads: 9
Joined: Aug 2007
Hi Vincze,
in the good old days, one would take a piece of paper, write down the registers
T

Z

Y

X

and the variables
D

X
and fill in the values they assume after each program step. I hope you will find this instructive. Best of all, you can do it yourself immediately and don't have to wait for a reply from some forum.
Cheers, Peter.
Edited: 24 Aug 2007, 9:18 a.m.
▼
Posts: 376
Threads: 35
Joined: Jul 2007
That very good tip, thank you my friend. I have question about two steps though. What is difference between D004 and D008? Do they not do same thing? If I understand correctly, after you hit SOLVE X, it go to line D001, which run through D program and call F program on line D004 and line D008?
Edited: 24 Aug 2007, 9:47 a.m.
▼
Posts: 1,830
Threads: 113
Joined: Aug 2005
If you key that into an HP35s, the D008 line will become 'XEQ F001' so yes, they are identical.
Regards, Howard
Posts: 217
Threads: 21
Joined: Aug 2007
The fact that F(x) > 0 where F'(x) = 0 doesn't mean that F(x) is increasing after zero.
Consider the curve, G(x) = 3*x^22*x+1. G'(x) = 0 at x=1/3, G(1/3) = 4/3. Here too G(x) > 0 where G'(x) = 0, yet G(x) decreases to either side of this point.
As far as the D program goes, here it is with comments:
D001 LBL D
D002 RCL D
D003 STO+ X // add value of D to value in X
D004 XEQ F001 // compute F(x+D)
D005 x<>y // bring D back into the x stack register
D006 STO X // subtract from value in X to restore x
D007 x<>y // bring F(x+D) back into x stack register
D008 XEQ F // compute F(x)
D009  // compute F(x+D)  F(x)
D010 RCL/ D // compute (F(x+D)  F(x)) / D
D011 RTN
This could probably be made shorter, but I didn't want to make it too unclear.
Stefan
▼
Posts: 376
Threads: 35
Joined: Jul 2007
Thank you my friend, this very interesting. I find it fascinating how effortlessly you conceptualize what calculator need to do and how calculator work. I still struggle with that.
Quote: The fact that F(x) > 0 where F'(x) = 0 doesn't mean that F(x) is increasing after zero.
I beg to differ my friend. When you set to zero and solve if you get positive, it mean you find minimum point on curve, and if you find negative, it mean maximum point on curve. At least that how we learn in Hungary, but result is still the same
In your examples if you plot out you will see. In first example, we get positive result when we solve for x when set to zero and the plot show curve going up after point where x=0. In second example, when we set to zero and solve for x, we get negative number. When we plot, you see that curve going down after point where x=0.
Regardless of this minor error in analyzing result, your program is very good and I kindly thank you!
Edited: 24 Aug 2007, 10:04 a.m.
▼
Posts: 55
Threads: 5
Joined: Jul 2007
As a good exercise: modify the program above to compute (F(x+d)F(xd))/2d
Numerical Recipes says it has better accuracy than (F(x+d)F(x))/d
Edited: 24 Aug 2007, 10:06 a.m.
▼
Posts: 217
Threads: 21
Joined: Aug 2007
Tried that, and you're right, it works better. Intuitively this makes sense, because you're estimating the derivative based on two points on either side of x, instead of x and a point further along.
I had to add a fair bit of extra code to D to make it work though. Unfortunately, the routine one passes to SOLVE isn't allowed to mess up the value of the register one is solving for, hence there's code that has to put it back the way it was. The revised D program is:
LBL D
RCL D
STO+ X
XEQ F // compute F(x+D)
x<>y
ENTER // compute 2D
+
STO X
x<>y
XEQ F // compute F(xD)

x<>y // setup to divide by 2D
÷
RCL D // restore X to original x value
STO+ X
x<>y // leave (F(x+D)F(xD))/2D on stack
RTN
Stefan
Edited: 24 Aug 2007, 11:00 a.m.
Posts: 217
Threads: 21
Joined: Aug 2007
Sorry, but you are mistaken. The following output is from the text version of Maple:
> g := 3*x^22*x+1;
2
g := 3 x  2 x + 1
> g1 := diff(g,x);
g1 := 6 x  2
> solve(g1=0,x);
1/3
> subs(x=1/3,g);
4/3
> plot(g,x=1..0.4);
AAAA +
AAA AAA +
AA AA +1.2
AA A +
A A+
AA *
A +1
AA +AA
A + AA
AA +0.8
AA + A
A + A
AA +0.6 A
A + A
AA + A
A +0.4 A
A + A
A + AA
A +0.2 A
A + A
A + A
*++++++++++++++++++++++++++++++++*++
+ AA
1 0.8 0.6 0.4 0.2 + 0.2 0.4
+ A
+0.2 A
+ A
The sign of G(x) for the value of x at which G'(x) = 0 has nothing to do with whether x is the location of a minimum or a maximum.
Stefan
▼
Posts: 260
Threads: 21
Joined: Nov 2006
If I lean back and squint, it looks like the display on my hp 50g.
Cheers,
Pal
Posts: 776
Threads: 25
Joined: Jun 2007
Quote: The sign of G(x) for the value of x at which G'(x) = 0 has nothing to do with whether x is the location of a minimum or a maximum
That's right. You have to either look at the curve, or, mathematically equivalently, take the second derivative and look at its sign.
