Solving for an Integral: 28S solution - 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: Solving for an Integral: 28S solution (/thread-133533.html) |
Solving for an Integral: 28S solution - Marcus von Cube, Germany - 02-28-2008 I'm referring here to Chuck's arc length problem which can be found here: Link to archive. The 28S solver and integrator work differently than in the later machines. Notably, integration can't be used as an algebraic function because it returns two values to the stack, the solution and the error. Failed algebraic attempt My first attempt was to create a wrapper to make integration an algebraic function:
<<The local variables fn, var, xl and xh aren't neccessary if you want to execute INTFN from the stack, because the values are fetched from the stack to fill the variables and are than put back in the same order. But the overhead is required by the algebraic syntax.
INTFN can be called like this: 'INTFN(v/(1+4*SQ(T)),T,0,2.3,.0001)'Due to the algebraic overhead, the function is relatively slow.
Now enter the solver menu: 'INTFN(v/(1+4*SQ(T)),T,0,X,EPS)-6'The resulting variables screen shows 'EPS', 'T' and 'X' as variables. In the parameterlist of INTFN, 'T' is a formal parameter, but the solver logic fails to see this and complains about an unset variable 'T' when I try to solve for 'X'. If I assign a value to 'T', integration fails bacause T is no longer accepted as a formal variable. So this is a dead end. :-( RPL solution
I decided that I had to go the RPL way. Integration works without a formal variable if the integrand is a program. Here is my solution: << -> x eps
FN can be called as an algebraic: 'FN(2.3,.0001)'This is faster than the original INTFN version.
Now enter the solver menu: 'FN(X,EPS)-6'The resulting variables screen shows 'EPS' and 'X' as a variables. You can now set the accuracy for the integration and solve for 'X'. The result appears within seconds. :) I didn't try the ROOT command but it should work likewise.
Marcus Edited: 28 Feb 2008, 4:43 a.m.
Re: Solving for an Integral: 28S solution - Karl Schneider - 02-28-2008 Hi, Marcus -- Again, good work! You provided a solution for the HP-28C/S, which has different protocol and lesser capabilities for integration than the successor HP-48 series. I'd mentioned this in a post from 18 Feb 2004 within the thread "RPL challenge -- area between two curves" (Archive #14):
Quote: You also demonstrated RPL-based integration of a program instead of an algebraic expression -- something I'd previously wondered how to do. That capability is very important, as some things aren't easy to incorporate into algebraic expressions. On the RPN side, the HP-32SII and its successors offer a choice of defining the integrand function by keystroke program or by algebraic expression; all other RPN models require a keystroke program. I trust that you noticed my solution for the TI-82 (14 Feb 2008), which I based upon your TI-92/Voyage solution. BTW, I find those one-liners clearer than the HP-71 solution, mainly for the absence of the latter's required variable names "IVAR" and "FVAR". However, the TI-82 (at least) cannot perform nested multiple integrations, while the older HP-71 can. -- KS
Edited: 28 Feb 2008, 3:48 p.m.
Re: Solving for an Integral: Optimization for speed. - Marcus von Cube, Germany - 03-02-2008 Karl, thank you for the nice words. I was recently thinking about how the algorithm could be made a little speedier and came to a solution which works in RPL as well as for the 35s in RPN. The most time is spend in the numerical integration. The first improvement in this special case is to make use of the fact that the derivative of an integral is simply the integrand. Valentin has already jumped in and has modified his generic Newton solver for the 35s. Numerical solvers iterate in a way that the X value approximates the solution in ever smaller intervalls. This lead me to another simplification: Integral from 0 to Xn f(t)dt is the same as the sum of Integral from 0 to Xn-1 f(t)dt and Integral from Xn-1 to Xn f(t)dt. So, instead of computing the numerical integral between 0 and Xn in each iteration, the program can simply save a copy of the last argument and integral value and add the difference in each step. The integration is faster for smaller intervalls as long as the required accuracy is given as an absolute (not relative) value. It works out for both the 35s and 28S.
My 35S-Implementation: LBL F CHK=188F, LN=29 "IntegrandFlag 1 decides whether to use the standard (set) or improved (clear) version. Here is my modfied 28S solution:
<< -> x eps If you solve 'FN2(X,EPS)-6' you'll see X, EPS, RS and XL on the menu. RS is the last ReSult, XL ist the Last X value. You need to initialize these by storing 0 to both or storing 0 to X and evaluating the expression once.
The speed improvements are noticable: Depending on the given starting value and accuracy (by display format or variable EPS) the running times can be as little as 25% of the original version. Edited: 2 Mar 2008, 4:54 p.m.
|