![]() |
Impressive TI NSpire CX CAS Multiple Integration - 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: Impressive TI NSpire CX CAS Multiple Integration (/thread-207178.html) |
Impressive TI NSpire CX CAS Multiple Integration - Namir - 12-18-2011 I have been playing with double and tripLE integration using the Monte Carlo method and with nested Simpson 1/3 rules using Excel VBA. The Monte Carlo method is very easy to program. Both methods work well, with the nested Simpson method performing better than the Monte Carlo for the same number of function calls. Out of curiosity, I powered up my TI Nspire CX CAS (the newest version) and tried to perform double and triple integrations. To my surprised, the machine gave me the correct answer in both cases, instead of complaining that it could only do single integration! Very impressive TI! Sorry 15C, you no can do!!!
Namir
Re: Impressive TI NSpire CX CAS Multiple Integration - Crawl - 12-18-2011 Pretty sure the TI89 and HP50g can do multiple integration out of the box, too.
No idea what the point of your last line was. Obviously the HP15C can't do any symbolic integrals, and while it might not be able to do triple integrals numerically out of the box, I'm sure such abilities can be programmed.
Re: Impressive TI NSpire CX CAS Multiple Integration - Namir - 12-18-2011 I certaily would like to see an HP-15C program that uses the built-in Integrate feature to perform multiple integration.
Re: Impressive TI NSpire CX CAS Multiple Integration - Oliver Unter Ecker - 12-19-2011 Hi Namir,
Can you show us the examples you tried? Does it work for both definite and indefinite integrals? Have you been seeing it fail for some other examples? (Would like to see those, too.)
Thanks!
Re: Impressive TI NSpire CX CAS Multiple Integration - Valentin Albillo - 12-19-2011 Quote: The HP-34C Solution Book "Advanced Math” features a program of mine which does exactly that to implement double integrals on the HP-34C, using 3-point Gauss for the outer integral and the built-in integration capability for the inner one. Though specifically written for the HP-34C it can be ported to the HP-15C with little or no change. Come to that, the same applies to all programs featured in the book, but if you're interested just in the particular one which computes double integrals and you can't find the Solutions Book, it's also featured here: http://membres.multimania.fr/albillo/calc/pdf/DatafileVA024.pdf
Best regards from V.
Edited: 19 Dec 2011, 6:43 a.m.
Re: Impressive TI NSpire CX CAS Multiple Integration - Namir - 12-19-2011 I tried the simple integrals:
/ \ 1 / \ 1 Re: Impressive TI NSpire CX CAS Multiple Integration - Namir - 12-19-2011 Thank you Valentin! Your article has definitely answered my question!
Namir
Re: Impressive TI NSpire CX CAS Multiple Integration - Crawl - 12-19-2011 Quote: Monte Carlo eventually wins, because the error goes as 1 over the square root of the number of function evaluations, [i]regardless of the dimension of the integral[i]. On the other hand, with nested Simpsons, error goes as 1 over the number of function evaluations raised to the (4/dimension) power.
So when you have 8 dimension integrals, Monte Carlo and Simpsons are equally good. For 9 or more dimension integrals, Monte Carlo is better.
Re: Impressive TI NSpire CX CAS Multiple Integration - Ángel Martin - 12-19-2011 Very portable to the 41/Advantage as well, and running great on the CL ;-)
Cheers, Re: Impressive TI NSpire CX CAS Multiple Integration - Valentin Albillo - 12-19-2011 Quote: You're welcome. If you're interested in testing out some particular methods against hard multiple integrals you may want to check problems 6, 7, and 10 in this interesting paper: http://crd.lbl.gov/~dhbailey/dhbpapers/tenproblems.pdf Problem 7 in particular, I included in this ancient post where I gave both the HP-71B MATH ROM implementation as well as a simple Monte-Carlo BASIC implementation: http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/archv014.cgi?read=53268
Best regards from V. Syntax on the 50g - Oliver Unter Ecker - 12-19-2011 Thanks. (I was secretly hoping for something a bit more exciting...) How about the syntax on the TI? On the 50g, I notice that 'S(11,14,X^2+4*Y,X)' EVAL works, whereas 'S(7,10,S(11,14,X^2+4*Y,X),Y)' does *not* enter. ("Invalid syntax" is reported.) In an RPL program, one could feed the (symbolic) output of the inner integral into the outer integral. So, yes, as per Crawl, there is out-of-box capability for multiple integration on the 50g. (On ND2, in development, S(7,10,S(11,14,X^2+4*Y,X),Y) works and returns 1719.)
["S" is my poor man's integral symbol.]
Re: Syntax on the 50g - Crawl - 12-19-2011 It should work. My tip for figuring out the syntax on the HP50g is to enter an expression in the equation editor (which is usually intuitive), but if you don't like that and want the "code", turn off "textbook" in display. That gave me 'S(7,10,S(11,14,(x^2)+(4*y),x),y)' which evaluates to 1719 I'm not able to duplicate your error. It enters fine (on the stack) even if I enter what you have (which is identical to what I have, minus the extra parenthesis) Maybe you just made a typo on the calculator?
Or maybe there's a mode difference, but I don't know which mode should make a difference, or why.
Re: Syntax on the 50g - Crawl - 12-19-2011 Quote:
And, actually, that's only because I had the "show all parens" flag checked. Without it, it looks absolutely identical to what you had.
Re: Syntax on the 50g - Oliver Unter Ecker - 12-19-2011 Thanks, Crawl.
You're right. It's all good. 'S(7,10,S(11,14,X^2+4*Y,X),Y and expected auto-completion to provide the closing chars for me, but, that, apparently, doesn't work in this instance and caused the syntax error.
(Yes, I'm that lazy/trusting of auto-completion...) Edited: 19 Dec 2011, 2:32 p.m.
Re: Impressive TI NSpire CX CAS Multiple Integration - Ángel Martin - 12-19-2011 Here´s the listing for the 41 version - in case you wonder:-
1. store number of intervals in R10, set FIX for precision
Enjoy,
01 LBL "2DITG"
Edited: 19 Dec 2011, 2:57 p.m.
Re: Impressive TI NSpire CX CAS Multiple Integration - Valentin Albillo - 12-19-2011 Hi, Ángel: Thanks for your interest and for the translation. Matter of fact this simple program translates with minimal effort to run in many other RPN models (HP-34C, HP-15C, HP-41** + Advantage ROM, etc) and an HP-71B version would be equally straightforward but moot as the INTEGRATE keyword (a funny function) allows for up to 5-dimensional integrals per se. A useful template to compute multiple integrals with the HP-71B plus examples can be found at point 10 in one of my articles, namely: http://membres.multimania.fr/albillo/calc/pdf/DatafileVA012.pdf By the way, I don't remember whether I've already ranted about this here but I think that the HP programmer (or team) who decided to name the keywords INTEGRATE instead of INTEG, FNROOT instead of SOLVE, FVAR instead of FV, and IVAR instead of IV had absolutely no idea of what "ergonomic" and "economic" mean, as the shorter keywords are faster to type and most importantly you can fit more complex expressions in the command line for immediate execution without the hassle of having to write a program just because your expression doesn't fit in a line (which is easily the case with multiple integrals).
Best regards from V.
Edited: 19 Dec 2011, 4:33 p.m.
Multiple Integration - WP 34S - Marcus von Cube, Germany - 12-19-2011 With the recent addition of local registers and recursive programming, WP 34S has the ability to do multiple integration with the built-in integrator (a non adaptive Gauss-Kronrod quadrature). I've not done it, but it should be straight forward to write a subroutine for the function to integrate and another which calls the integrator for the defined function. This subroutine can than be used as the argument for the integrator. Not as comfortable as just typing in a formula but still easier than creating your own integrator in RPN.
Re: Syntax on the 50g - Crawl - 12-19-2011 Quote: It's pretty intuitive on the TI89. Just nest the integrals like on the HP50g (except that the limits come at the end rather than the beginning of the syntax)
Re: Syntax on the 50g - Oliver Unter Ecker - 12-20-2011 Thanks for that, Crawl.
Makes sense. I had wondered if there might be, perhaps, a special "SS" syntax.
Re: Syntax on the 50g - Crawl - 12-20-2011 The problem with that approach is that you then wouldn't be able to do quadruple, quintuple, etc., integrals. The great thing about the CAS in these modern calculators is that they're fully integrated, so you can (for example) combine complex numbers with symbolic expressions in matrices, or (as in this case) combine integrals with integrals to do multiple integration, etc.
There's probably no limit to the number of integrals you can nest, other than calculator memory and the increasing amount of time it would take to evaluate them.
Re: Multiple Integration - WP 34S - Marcus von Cube, Germany - 12-20-2011 Here is a short example of a recursive call to the WP 34S integrator. It computes S(0,1,S(0,1 X*Y,Y),X). The result is 0.25. No global registers are used, the outer subroutine at LBL 00 creates a local register .00 which is visible to the inner subroutine at LBL 01.
LBL A Re: Impressive TI NSpire CX CAS Multiple Integration - Crawl - 12-20-2011 I tried the 6-dimensional integral of tan(x*y*z*t*a*b) over x,y,z,t,a,b, all variables ranging between 0 and 1. In maybe about a minute I set up an Excel spreadsheet that calculated it with Monte Carlo simulation (30K points), getting 0.015.
Anyway care to try to do better?
Re: Impressive TI NSpire CX CAS Multiple Integration - Valentin Albillo - 12-20-2011 Quote: Well, this extremely simple HP-71B Monte Carlo code (80+ bytes):
10 DESTROY ALL @ RANDOMIZE 1 @ RADIANS
repeatably runs to give: >RUN which agrees with your result. The final value should have about Log10(Sqrt(1000000)) = 3 correct digits so 0.0157 should be accurate to all the digits shown. Curiously enough, the final value ( 0.015709 ) closely resembles Pi/200 = 0.015708 ... I'll let you figure out whether that's a coincidence or not ... :D
Best regards from V.
Re: Impressive TI NSpire CX CAS Multiple Integration - Oliver Unter Ecker - 12-20-2011 I had W|A try better. integrate (integrate (integrate (integrate (integrate (integrate (tan(x*y*z*t*a*b)) First it wanted more time, then it volunteered another server, as the first decided to quit. (Again! It's pretty easy to get into that condition with W|A. I wonder if it really, physically, brings down a server. The icon of a server farm suggests as much to me.) Maybe there's a better question to ask W|A that will return a result.
Anyway. See, that's where "SSSSSS" syntax may be useful: for higher dimensions, switch to an altogether different algorithm. Here: Monte Carlo. Here's home-baked Monte-Carlo in RPL+:
\<< 5 =l
Returns 0.015xxx, with latter digits varying by run, in ~7s on my iPhone. [Crawl: Off-topic, but since you had responded to my question about modular exponentation of a non-integer and the thread is archived: Here's how that played out: As suspected, this was not about any non-integer. The polynomial was special, and so were its roots. The secret sauce knowledge to have was about Pisot numbers, and Newton's Identities. Took me *weeks* to figure out, even with hints... but ultimately a great problem to solve. And running on an app calc in 1s/root.] [EDIT: Added RPL+ code.]
Edited: 20 Dec 2011, 7:56 p.m.
Re: Impressive TI NSpire CX CAS Multiple Integration - Gerson W. Barbosa - 12-20-2011
Quote: It will understand the following syntax:
integrate tan(x*y*z*t*a*b) dx dy dz dt da db, x=0..1, y=0..1, z=0..1, t=0..1, a=0..1, b=0..1 However, this is all it gives out: Computation timed out. No more results available. which might mean Buy Mathematica, buy Mathematica... :-)
Re: Impressive TI NSpire CX CAS Multiple Integration - Thomas Klemm - 12-21-2011 Quote:
I used the Taylor expansion of tan(x) (up to the term of x19) and got: 1.57094692997E-2 Compared to Pi/200 I'd say: coincidence.
Kind regards Re: Impressive TI NSpire CX CAS Multiple Integration - Valentin Albillo - 12-21-2011 Quote: Surely it does. W/A, while being an outstanding piece of software and a very useful one at that, also fails miserably in many surprisingly simple computational tasks with the added puzzlement that sometimes it will work alright for a very slight variation of the computation that's giving it the bends. I initially submitted a lot of reports but never received a reply or noticed any action at all being taken on them so I don't bother anymore.
Best regards from V. Re: Impressive TI NSpire CX CAS Multiple Integration - Valentin Albillo - 12-21-2011 Quote:
Trying that syntax out in W/A with the 2-dimensional version, namely: integrate tan(x*y) dx dy, x=0..1, y=0..1produces 0.275687 after a while and refuses to compute any more digits ("Computation timed out") which is pretty useless for identification purposes.
On the other hand, the HP-71B produces with the help of just a little code (and my constant recognition program): > CAT which seems quite a reasonable agreement as the alleged symbolic identification evaluates to .275687273774, i.e., a 10-digit agreement with the numerically computed value for the double integral. Whether the symbolic identification is absolutely correct would require many more digits and that would only serve as empirical reassuring, never proof, that would demand symbolics. Oh, and by the way, a Monte-Carlo run with 107samples produces .275716754735, which is good to nearly 5 digits, not bad for a dumb probabilistic method.
Best regards from V.
Edited: 21 Dec 2011, 4:50 p.m.
Re: Impressive TI NSpire CX CAS Multiple Integration - Gerson W. Barbosa - 12-21-2011 Hello Valentin,
Quote: I had tried that on W|A but I failed to notice any connection to pi. I had divided 0.275687 by pi on the HP-32SII and obtained 8.77538976e-2. Had I divided it again by pi I would have gotten 2.79329332e-2. Finally FDISP would have returned 0 5/179. Best regards, Gerson. P.S.: By the way, one of these days I observed e^(e*pi) = 5113.98499978, which multiplied by 200 equals 1022796.99996. A coincidence?
Edited: 21 Dec 2011, 5:43 p.m.
Re: Impressive TI NSpire CX CAS Multiple Integration - Gerson W. Barbosa - 12-22-2011 Quote: W|A returns "integral tan(x y) dx = -(log(cos(x y)))/y+constant" for "integrate tan(x*y) dx". We can use the HP-15C
f LBL A and get
0 ENTER 1 Integrate A CHS -> 0.2756872439 We can also try this online integrator and obtain
Numerical Integration of -(log(cos(x)))/x in the interval [0,1]
which is remarkably close to 5/179*pi^2: 0.2756872737734458 Best regards, Gerson.
Re: Impressive TI NSpire CX CAS Multiple Integration - Crawl - 12-22-2011 Thomas Klemm probably has the winning technique. I'll post some solutions one at a time since it'll take a while to get it all together. This is Simpsons's Rule on an HP50g. First you need this program
%%HP: T(3)A(R)F(.); which I named SIMPCO. Then this is the program you run:
%%HP: T(3)A(R)F(.); I named it SIMP6, but it doesn't really matter what you name it. You give as an argument an even number (t). It will do (t/2) applications of Simpsons rule in each dimension, which works out to (t+1)^6 function evaluations. Results:
t Calculation Result Time on Calculator Time on Emulator You probably could do the t=6 case on an actual calculator, provided you were willing to let it run for 6 or 7 hours. Better use USB power.
Edited: 22 Dec 2011, 4:54 p.m.
Re: Impressive TI NSpire CX CAS Multiple Integration - Crawl - 12-22-2011 Here's the Taylor series solution.
%%HP: T(3)A(R)F(.); The argument is the number of terms to take in the Taylor series. And results:
t Result Calculator Time Emulator Time
Also, I'm getting slight differences between the physical and the emulator. The emulator gives a result 1ulp less for the t=19 and 29 cases I checked on both. Edited: 22 Dec 2011, 6:15 p.m.
Re: Impressive TI NSpire CX CAS Multiple Integration - Crawl - 12-22-2011 And this compares the absolute error between using the Monte Carlo method versus Simpson's Rule.
Even for this problem, Simpson's Rule is more efficient than Monte Carlo.
Re: Impressive TI NSpire CX CAS Multiple Integration - Thomas Klemm - 12-23-2011 Is it possible to just calculate the coefficients of the Taylor series using the HP-50G? I was trying to do that using the HP-48G without success. So I let WolframAlpha do this and entered them into the HP-42S which was quite a pain, you may believe me. Once I have stored them into the registers 01, 02, ... I used the following program:
00 { 33-Byte Prgm } To run the program you just enter the dimension, in this case n = 6. With minor changes this program could be used with the HP-15C and most other models as well. So yes, with only a little cheating (i.e. using W|A for the coefficients) we can do multiple integration. Purists would first write a program to calculate the Bernoulli-numbers to get the coefficients without that ugly hack. Now I'm curious how the TI NSpire CX handles this problem. This Taylor expansion converges only slowly for the upper bound x = 1. Therefore I tried to find a substitution that might transform that to something like 1/2 but to no avail. Maybe somebody else has an idea? Since the quotient of succeding coefficents ai/ai+1 converges to (Pi/2)2 some kind of convergence acceleration could be helpful but I didn't try that. Here we're just lucky because n = 6: the harder you're trying to make it by adding more dimensions, the faster it converges.
Kind regards
Edited: 23 Dec 2011, 12:47 a.m.
Re: Impressive TI NSpire CX CAS Multiple Integration - Thomas Klemm - 12-23-2011
Quote: For those too lazy to enter those numbers manually but still willing to enter a program into the calculator:
00 { 49-Byte Prgm } Now you enter the following:
1
Just keep on pressing [R/S] until you feel like it's enough, let's assume stop with 20. BTW: In the end I didn't use the Bernoulli-numbers but simply the fact that: sin(x) = cos(x) tan(x). This gives a system of equations for the unknown coefficients of tan(x). So I hope the purists are happy now.
Cheers Re: Impressive TI NSpire CX CAS Multiple Integration - Thomas Klemm - 12-23-2011 Quote: My experiences with WolframAlpha were positive: I once reported a bug and was informed some time later, when it was fixed. So I encourage reporting them.
Kind regards Re: Impressive TI NSpire CX CAS Multiple Integration - Valentin Albillo - 12-23-2011 Quote:
Hehe, no need for a lousy online integrator, my very own integrator produces: Integral[-log(cos(x))/x] in [0,1] = 0.275687273800437163889752061421593272955579883796079969049093394140279534475580649396385056763317646349196which, as I stated, is remarkably close to:
5*pi^2/179 = 0.275687273773445771475823770946261204897030709699463425318808641793856000626234783324071882785434419883352 so both values aren't identical though in this case I don't think their similarity is coincidental. Thanks for your interest and
Best regards from V. Re: Impressive TI NSpire CX CAS Multiple Integration - Thomas Klemm - 12-23-2011 Using the Taylor expansion of tan(x) I can confirm this result. With Free42 we have something like 20 internal figures; I forgot the exact number. When I take the first 100 terms into account I get the following value for n = 2:
0.2756872738004371638897521
Cheers Re: Impressive TI NSpire CX CAS Multiple Integration - Oliver Unter Ecker - 12-23-2011 Nice job, Crawl.
I tried your code, unchanged, on my calcs. t Calculation Result Time on ND1 Time on CalcPad/Mac
Then I gave it a quick speed treatment. f(N,F,T)=F * (N%2 ? 4 : (N && N != T ? 2 : 1)) Then I changed some RPL instructions into RPL+ for SIMP6: \<< 0 \-> T S New timings: t Calculation Result Time on ND1 Time on CalcPad/Mac
Edited: 23 Dec 2011, 7:12 p.m.
Re: Impressive TI NSpire CX CAS Multiple Integration - Crawl - 12-23-2011 Another thing you could try would be to just enter the integral as-is and try to let the built-in integral routines try to deal with it.
I think we have evidence here that you should be able to get at least a few digits of accuracy this way, and by adjusting the FIX setting you can only ask for a few.
You don't really need a program for this, but this lets the calculator time itself, and I can also just let it run and do something else and have the calculator alert me when it's finished.
Fix Returned Full Time (with Emulator) I didn't even bother trying this with a physical calculator.
Edited: 23 Dec 2011, 6:21 p.m.
Re: Impressive TI NSpire CX CAS Multiple Integration - Crawl - 12-23-2011 Quote:
Yes, it can. I don't know about the 48.
Re: Impressive TI NSpire CX CAS Multiple Integration - Oliver Unter Ecker - 12-23-2011 A further 3x speed improvement is obtained by changing this RPL code A B C D E F * * * * * T 6 ^ / TAN T 3 * 6 ^ / P6 *
into this RPL+ code P6*TAN((A*B*C*D*E*F)/T^6)/(T*3)^6
Another 10% is squeezed out by writing SIMPSO in JavaScript, like so: function (N, F, T) { /*as is*/ The improved timings: t Calculation Result Time on ND1 Time on CalcPad/Mac
That's ~500x faster than a 50g for this task, on <10x faster HW (iPhone vs. 50g HW). Edited: 23 Dec 2011, 7:45 p.m.
Re: Impressive TI NSpire CX CAS Multiple Integration - Crawl - 12-24-2011 The FIX5 case finally stopped running. The clock says it took 25 hours, 13 minutes, but that's very approximate, since the computer was in sleep mode several times over that period. The result is
1.57094677879e-2
Re: Impressive TI NSpire CX CAS Multiple Integration - Thomas Klemm - 12-25-2011 Quote: That's amazing! Just for comparison: it takes ~60ms for Free42 on my iPhone to calculate this integral to 16 correct places (both "INIT" and "ITAN") when I use 20 terms to get:
1.570946930078026084759965e-2 However with 40 terms it takes ~240ms to produce 24 correct places1:
1.57094693007802638993157e-2 Just imagine how long it would take to do that with your method.
Cheers
1. Of course I can't be sure whether all places are correct, but it's the case for n = 1 compared to -log(cos(1)) and n = 2 compared to Valentin's result when I use 100 terms. Therefore I assume the coefficients of the Taylor series are correct. And with n = 6 fewer terms are needed to get the same result. |