sum command... - Printable Version +- HP Forums ( https://www.hpmuseum.org/forum)+-- Forum: HP Calculators (and very old HP Computers) ( /forum-3.html)+--- Forum: HP Prime ( /forum-5.html)+--- Thread: sum command... ( /thread-9276.html) |

sum command... - webmasterpdx - 10-11-2017 05:01 AM
When I try to evaluate sum(1/x^2,x,1,n), if n = infinity, it evaluates correctly to pi^2/6, but when i put n = 100, 1000, 2000, it calculates it as these giant fractions, which I have to run approx() on to get the decimal value. Then, when I try n = 5000, it runs out of space for the numerator and denominator, and gives me an answer of undef, instead of trying to calculate the decimal answer.... Wondering why it's trying to evaluate this as a huge fraction instead of decimally? and why it's coming up with an answer of undef instead of calculating the correct value? Thx -Donald RE: sum command... - parisse - 10-11-2017 05:06 AM
If you want an approx value, enter one approx bound, for example sum(1/x^2,x,1,5000.) Same for integration. RE: sum command... - AlexFekken - 10-11-2017 05:14 AM
My guess would be that it is because you are using CAS and are exceeding its limits. If you want numerical calculations you should use Home. And preferably sum back to front (if you can control that). RE: sum command... - webmasterpdx - 10-11-2017 09:07 AM
Of course I'm exceeding CAS limits, but why is it calculating it as a ratio? I would imagine or want the SUM function to work like this pseudocode: sum = 0; for x=1 to 5000 sum = sum + expression; endfor Clearly, that's not how it's being evaluated....which is kinda weird. I tried running this in home: sum(1/x^2, x, 1, 1000) It gave be a bizarre ratio as an answer of 9.9999e499 as both numerator and denominator... I was able to run approx(sum(1/x^2,x,1,1000)), and that worked....result was 1.6439.. ....with 5000, I get undef in home mode too... RE: sum command... - Didier Lachieze - 10-11-2017 09:26 AM
sum is a CAS command. in Home try to use Σ instead (from the math template key). For ex: Σ(1/X^2,X,1,5000) RE: sum command... - webmasterpdx - 10-11-2017 10:19 AM
Wow.....sigma is really fast too...Thx! RE: sum command... - AlexFekken - 10-11-2017 12:25 PM
(10-11-2017 09:07 AM)webmasterpdx Wrote: Of course I'm exceeding CAS limits, but why is it calculating it as a ratio? How else would it (try to) do an exact calculation? What would you expect it to do? (10-11-2017 09:07 AM)webmasterpdx Wrote: I would imagine or want the SUM function to work like this pseudocode: That's probably exactly what it does, or tries to do. Why would you assume that it doesn't? RE: sum command... - webmasterpdx - 10-11-2017 01:41 PM
It doesn't act like that pseudocode. It has to calculate it so it can handle an algebraic sum and get algebraic results....which is a lot more sophisticated. To do it like the pseudocode, you use the Σ function in Home as Didier suggests.... RE: sum command... - AlexFekken - 10-11-2017 11:11 PM
(10-11-2017 01:41 PM)webmasterpdx Wrote: It doesn't act like that pseudocode. It has to calculate it so it can handle an algebraic sum and get algebraic results....which is a lot more sophisticated.I have no problem with "sophisticated", but I do have a problem with arguments based on what one of my professors used to call "proof by mathematical intimidation". :-) Can you pleae explain what you mean? In the mean time: [1] By providing an explicit upper bound (5000) you were asking for a rational number, not an algebraic expression. So regardless of the algortihm being used why would you complain about CAS trying to give you exactly what you asked for? [2] If you are trying to suggest that there should be a magical short-cut to doing the calculation, similar to when you would be adding n^2 instead of n^(-2), then I doubt that one exists. But that's just based on my gut feeling, so feel free to correct me. Of course that would not change the fact that in the end you are still asking for a rational number. The very worst thing CAS could do is to silently slip out of exact mode and give me an approximation when I clearly asked for an exact result (or I would be using Home mode). RE: sum command... - webmasterpdx - 10-12-2017 01:13 AM
I'm not a CAS expert, so you could look at the XCas source code if you really want to see how it does it, but I do know if you try the sum() function with arguments that are functions of different variables, it'll be a lot more complex than simply calling the same function over and over again. e.g. This SUM(1/y^2,y,x,1000x) results in Psi(x,1)-Psi(1000*x+1,1). The sigma function is way way faster as it's just doing what that pseudocode does (calling the same function over and over again). e.g. Sum with an upper limit of 5000 takes about 20 seconds, but sigma returns an answer immediately. FYI, the XCas source code is here... https://www-fourier.ujf-grenoble.fr/~parisse/giac/src/ RE: sum command... - AlexFekken - 10-12-2017 05:04 AM
Ah, the plot thickens... The "sophisticated" and "complex" work that you are referring to is simply a re-labelling of the partial sum. It does not do anything significant other than putting a name to the partial sums so that it looks "nicer" when you are using variable bounds. But your original post isn't about that, it is about calculations with explicit bounds and the Psi function isn't going to help you one bit there, whereas actually doing the sum by going through the loop does (if it doesn't bump into its limitations first). RE: sum command... - parisse - 10-12-2017 06:23 AM
(10-12-2017 01:13 AM)webmasterpdx Wrote: FYI, the XCas source code is here... I would instead recommend giac in geogebra svn RE: sum command... - AlexFekken - 10-12-2017 06:38 AM
(10-12-2017 06:23 AM)parisse Wrote:Thanks.(10-12-2017 01:13 AM)webmasterpdx Wrote: FYI, the XCas source code is here... RE: sum command... - webmasterpdx - 10-12-2017 07:18 AM
Is this the official XCas source SVN database? RE: sum command... - DrD - 10-12-2017 09:29 AM
Keep in mind as you download and refer to various documents, the CAS changes. There have been a lot of, "fixed in source" notes on this forum, and perhaps many more changes behind the scenes. It may not be current code, to whatever conclusions that may take a reader. RE: sum command... - parisse - 10-12-2017 12:10 PM
(10-12-2017 07:18 AM)webmasterpdx Wrote: Is this the official XCas source SVN database?There is no official SVN source for Xcas, but a tarball on my webpage. The geogebra SVN contains the giac source code without the UI, and I maintain it up to date. Since the UI is not used on the Prime, I recommend it. RE: sum command... - webmasterpdx - 10-12-2017 01:02 PM
OK. Thats the one I've set the wiki to point to... http://www.wiki4hp.com/doku.php?id=prime:start |