HP49-50G plotting of sum(x=0 to 0, 1, 2,...10, of x!/(2x)!)
11-05-2023, 01:33 PM (This post was last modified: 11-05-2023 01:34 PM by Gil.)
Post: #1
 Gil Senior Member Posts: 624 Joined: Oct 2019
HP49-50G plotting of sum(x=0 to 0, 1, 2,...10, of x!/(2x)!)
I want to plot the function, for x=integer,

Y= sum (from x=0 to 0, of x! / (2x)!) [1st point]
Y= sum (from x=0 to 1, of x! / (2x)!) [2nd point]
Y= sum (from x=0 to 2, of x! / (2x)!) [3rd point]
...
Y= sum (from x=10 to 0, of x! / (2x)!) [11th point]

in order to see how this series converges

Basically, the program is
« 0 0 X
FOR i i ! SQ 2 i * ! / +
NEXT
»
and Range X goes from 0 to 11.

For each intermediary step (before NEXT command), I want the corresponding value yi to be drawn (point xi, yi).

How should I procede to enter Y1=...?

Thanks in advance for your kind help.

Regards,
Gil
11-05-2023, 02:13 PM
Post: #2
 Gil Senior Member Posts: 624 Joined: Oct 2019
RE: HP49-50G plotting of sum(x=0 to 0, 1, 2,...10, of x!/(2x)!)
My solution :

Use a scatter function
building beforehand a SDAT Matrix as follows (for eleven points) :

« 'DAT' PURGE 0 0 11
FOR i i ! SQ 2 i * ! / + NUM DUP i SWAP 2 ARRY +
NEXT
»

\<< '\GSDAT' PURGE 0 0 11
FOR i i ! SQ 2 i * ! / + \->NUM DUP i SWAP 2 \->ARRY \GS+
NEXT
\>>

Question : is there a better, more simple way?

Gil
11-05-2023, 04:13 PM
Post: #3
 Eddie W. Shore Senior Member Posts: 1,590 Joined: Dec 2013
RE: HP49-50G plotting of sum(x=0 to 0, 1, 2,...10, of x!/(2x)!)
I was also thinking scatterplot.
11-05-2023, 06:03 PM
Post: #4
 Thomas Klemm Senior Member Posts: 2,104 Joined: Dec 2013
RE: HP49-50G plotting of sum(x=0 to 0, 1, 2,...10, of x!/(2x)!)
The factorial $$k!$$ in the numerator can be shortened.
So we get:

\begin{align} \sum_{k=0}^\infty \frac{k!}{(2 k)!} &= 1 + \frac{\frac{1}{2^1}}{1} + \frac{\frac{1}{2^2}}{1 \cdot 3} + \frac{\frac{1}{2^3}}{1 \cdot 3 \cdot 5} + \frac{\frac{1}{2^4}}{1 \cdot 3 \cdot 5 \cdot 7} + \cdots \end{align}

This reminded me of this Mathologer video:

At 9:00 he finds a closed formula:

\begin{align} e^{\frac{x^2}{2}} \int_0^x e^{\frac{-t^2}{2}} \mathrm{d} t &= \frac{x}{1} + \frac{x^3}{1 \cdot 3} + \frac{x^5}{1 \cdot 3 \cdot 5} + \frac{x^7}{1 \cdot 3 \cdot 5 \cdot 7} + \cdots \end{align}

Multiply both sides by $$x$$ and substitute $$x^2 = \frac{1}{2}$$ to get the sum.
Well, not quite, but we are close to the goal.
We're still missing the initial $$1$$.

This is the result we get from WolframAlpha using the error function Erf:

Sum[k!/(2k)!, k]

\begin{align} \sum_{k=0}^\infty \frac{k!}{(2 k)!} = \frac{1}{2} \left( \sqrt[4]{e} \sqrt{\pi} \; \text{erf} \left( \frac{1}{2} \right) + 2 \right) \approx 1.5923 \end{align}

To match both results we can use that:

\begin{align} \int_0^{\frac{1}{\sqrt{2}}} e^{\frac{-t^2}{2}} \mathrm{d} t &= \sqrt{\frac{\pi}{2}} \; \text{erf} \left( \frac{1}{2} \right) \end{align}

(11-05-2023 01:33 PM)Gil Wrote:  in order to see how this series converges to about 1.7364.

Consistent with the result above, the series appears to converge to 1.592296536469326:
Code:
from math import factorial s = 0 [s := s + factorial(k)/factorial(2*k) for k in range(15)]

[1.0,
1.5,
1.5833333333333333,
1.5916666666666666,
1.5922619047619047,
1.5922949735449734,
1.5922964766714764,
1.5922965344840343,
1.5922965364111195,
1.5922965364677983,
1.5922965364692898,
1.5922965364693253,
1.592296536469326,
1.592296536469326,
1.592296536469326]
11-05-2023, 08:32 PM
Post: #5
 Albert Chan Senior Member Posts: 2,679 Joined: Jul 2018
RE: HP49-50G plotting of sum(x=0 to 0, 1, 2,...10, of x!/(2x)!)
(11-05-2023 06:03 PM)Thomas Klemm Wrote:  \begin{align} \sum_{k=0}^\infty \frac{k!}{(2 k)!} &= 1 + \frac{\frac{1}{2^1}}{1} + \frac{\frac{1}{2^2}}{1 \cdot 3} + \frac{\frac{1}{2^3}}{1 \cdot 3 \cdot 5} + \frac{\frac{1}{2^4}}{1 \cdot 3 \cdot 5 \cdot 7} + \cdots \end{align}

$\displaystyle \sum_{k=0}^\infty \frac{k!}{(2 k)!} = 1+\frac{1}{2} \left(1 + \frac{1}{6} \left( 1 + \frac{1}{10} \left( 1 + \frac{1}{14} \left(1 + \cdots \right)\right)\right)\right)$
10 K=2 @ D=K @ S=0
20 REPEAT @ 1+S @ S=S+1/D @ K=K+4 @ D=D*K @ UNTIL D+1=D
>run
1
1.5
1.58333333333
1.59166666667
1.59226190476
1.59229497354
1.59229647667
1.59229653448
1.59229653641
1.59229653647
11-05-2023, 10:39 PM
Post: #6
 Gil Senior Member Posts: 624 Joined: Oct 2019
RE: HP49-50G plotting of sum(x=0 to 0, 1, 2,...10, of x!/(2x)!)
Remark
What I reckoned with my code is
sum of (x!)² / (2x)!, with x=0, 1, 2...

But unfortunately I labelled wrongly the problem,
forgetting the square at the numerator,
so that that sum —> 1.59, as you pointed out.

Thanks for your contributions.
11-06-2023, 12:25 AM
Post: #7
 Thomas Klemm Senior Member Posts: 2,104 Joined: Dec 2013
RE: HP49-50G plotting of sum(x=0 to 0, 1, 2,...10, of x!/(2x)!)
(11-05-2023 10:39 PM)Gil Wrote:  forgetting the square at the numerator,

I was already wondering why that square was in the code.

This is probably not much better than your solution:
Code:
\<< CL\GS 0 0 11     FOR i         i ! SQ         2 i * ! / +         DUP \GS+     NEXT \>>

And then I used the BAR plot.
This works with an HP-48GX.

For Sum[(k!)^2/(2k)!, k] the result is:

\begin{align} \sum_{k=0}^\infty \frac{(k!)^2}{(2 k)!} = \frac{2}{27} \left(18 + \sqrt{3} \pi \right) \approx 1.73639985871872 \end{align}
11-06-2023, 01:31 AM
Post: #8
 Albert Chan Senior Member Posts: 2,679 Joined: Jul 2018
RE: HP49-50G plotting of sum(x=0 to 0, 1, 2,...10, of x!/(2x)!)
(11-05-2023 08:32 PM)Albert Chan Wrote:  $\displaystyle \sum_{k=0}^\infty \frac{k!}{(2 k)!} = 1+\frac{1}{2} \left(1 + \frac{1}{6} \left( 1 + \frac{1}{10} \left( 1 + \frac{1}{14} \left(1 + \cdots \right)\right)\right)\right)$

$\displaystyle \sum_{k=0}^\infty \frac{(k!)^2}{(2 k)!} = 1+\frac{1}{2} \left(1 + \frac{2}{6} \left( 1 + \frac{3}{10} \left( 1 + \frac{4}{14} \left(1 + \cdots \right)\right)\right)\right)$

10 K=2 @ D=K @ S=0
20 REPEAT @ DISP 1+S @ S=S+1/D @ K=K+4 @ D=D*K*4/(K+2) @ UNTIL D+1=D
>run
1
1.5
1.66666666667
1.71666666667
1.73095238095
1.73492063492
1.736002886
1.73629426129
1.73637196137
1.73639252904
1.73639794158
1.73639935916
1.7363998251
1.73639985003
1.73639985648
1.73639985814
1.73639985857
1.73639985868
1.73639985871
1.73639985872
11-06-2023, 04:18 PM
Post: #9
 DavidM Senior Member Posts: 988 Joined: Dec 2013
RE: HP49-50G plotting of sum(x=0 to 0, 1, 2,...10, of x!/(2x)!)
Since you asked specifically about how to do this on a 49/50, the following is an alternative for that platform that simply uses the given function without any substitution or simplification. I've used a program as opposed to an algebraic equation as the function to plot, just as you did. It would work in either form, but using a program provides a noticeable performance boost. This is frequently the case when graphing functions on these systems.

I've chosen to implement this as a FUNCTION plot for simplicity. This avoids the need for setting up and editing a table as is needed for a SCATTER plot.

At a high level, there are four steps:
1) Initialize the graph environment
2) Set the graphing parameters
3) Draw the graph
4) Determine the needed data point

Here's a sample program that sets up the graph for interactive assessment:
Code:
\<<   'PPAR' PURGE              @ we don't want any leftover PPAR settings   ERASE                     @ erase any previous plots   FUNCTION                  @ set the plot type to FUNCTION   -31 SF                    @ don't connect the plotted points   1. RES                    @ step value of 1 plots only the integer X values   \<<                       @ the function to be plotted should be stored in EQ     0.     DUP X FOR N       N ! SQ N 2 * ! /       +     NEXT   \>>   STEQ   0. 10. XRNG               @ by definition, X goes from 0 to 10   0. 2. YRNG                @ one possible Y-range that includes the target   DRAX DRAW                 @ draw the axes and plot the data points   PICTURE                   @ show the plot along with the graph tools menu \>>

Running the above program will plot the needed data points and activate PICTURE, which shows the resulting graph along with some tools in the menu:

Observing the plotted data, it appears that we may have an extremum on the far right. So let's see what that value is.

Move the cursor to the far right side with <right shift><right arrow>:

Press the F3/C key to activate TRACE mode. This will position the cursor on the right-most plotted data point:

(optional) Press the F2/B key to activate (X,Y) mode. This shows the X/Y values for that data point:

Press ENTER to place the X-Y coordinates on the stack as an ordered pair, then press ON/CANCEL to leave the PICTURE environment:

In this case, the accuracy of the result can be improved by expanding the XRNG max parameter, which of course will increase the number of plotted data points.
11-06-2023, 04:28 PM
Post: #10
 Gil Senior Member Posts: 624 Joined: Oct 2019
RE: HP49-50G plotting of sum(x=0 to 0, 1, 2,...10, of x!/(2x)!)
Thanks, David, for your nice, detailed solution.

It's exactly what I was looking for.

With my best regards,
Gil
11-15-2023, 05:53 PM
Post: #11
 Thomas Klemm Senior Member Posts: 2,104 Joined: Dec 2013
RE: HP49-50G plotting of sum(x=0 to 0, 1, 2,...10, of x!/(2x)!)
(11-06-2023 12:25 AM)Thomas Klemm Wrote:  For Sum[(k!)^2/(2k)!, k] the result is:

\begin{align} \sum_{k=0}^\infty \frac{(k!)^2}{(2 k)!} = \frac{2}{27} \left(18 + \sqrt{3} \pi \right) \approx 1.73639985871872 \end{align}

I was not able to find a closed solution for the associated generating function using WolframAlpha.
But after trying some values for $$x$$ I could guess it:

\begin{align} \sum_{k=0}^{\infty} \frac{(k!)^2}{(2k)!} \; x^k &= \frac{1 + \frac{\frac{\sqrt{x}}{2}}{\sqrt{1 - \frac{x}{4}}} \sin^{-1}\left( \frac{\sqrt{x}}{2}\right)}{1 - \frac{x}{4}} \end{align}

Examples

$$x = 1$$

\begin{align} \sum_{k=0}^{\infty} \frac{(k!)^2}{(2k)!} &= \frac{2}{27} \left(18 + \sqrt{3} \pi \right) \\ &\approx 1.736399858718715077909795 \\ \end{align}

$$x = 2$$

\begin{align} \sum_{k=0}^{\infty} \frac{(k!)^2}{(2k)!} \; 2^k &= \frac{4 + \pi}{2} \\ &\approx 3.570796326794896619231322 \\ \end{align}

$$x = 3$$

\begin{align} \sum_{k=0}^{\infty} \frac{(k!)^2}{(2k)!} \; 3^k &= \frac{4}{3} \left(3 + \sqrt{3} \pi \right) \\ &\approx 11.25519745693687140237631 \\ \end{align}

Differential Equation

I wondered how to find a differential equation based on the coefficients of the sequence.

Substitution

The formula above suggests the following substitution:

\begin{align} u &= \frac{\sqrt{x}}{2} \\ u^2 &= \frac{x}{4} \\ x &= 4u^2 \end{align}

We can also rewrite the coefficients using Double Factorials:

\begin{align} y(x) &= \sum_{k=0}^{\infty} \frac{(k!)^2}{(2k)!} \; x^k \\ \\ y(u) &= \sum_{k=0}^{\infty} \frac{(k!)^2}{(2k)!} \; 2^{2k} u^{2k} \\ \\ &= \sum_{k=0}^{\infty} \frac{((2k)!!)^2}{(2k)!} \; u^{2k} \\ \\ &= \sum_{k=0}^{\infty} \frac{(2k)!!}{(2k-1)!!} \; u^{2k} \\ \\ &= \sum_{k=0}^{\infty} a_{k} \; u^{2k} \\ \end{align}

Example

Here's an example of the transformation of the coefficient $$a_k$$ for $$k = 4$$:

\begin{align} \frac{(k!)^2}{(2k)!} \; 2^{2k} &= \frac{(1 \cdot 2 \cdot 3 \cdot 4)^2}{1 \cdot 2 \cdot 3 \cdot 4 \cdot 5 \cdot 6 \cdot 7 \cdot 8} \; 2^8 \\ \\ &= \frac{(1 \cdot 2 \cdot 3 \cdot 4)^2}{1 \cdot 2 \cdot 3 \cdot 4 \cdot 5 \cdot 6 \cdot 7 \cdot 8} \; \left( 2^4 \right)^2 \\ \\ &= \frac{(1 \cdot 2 \cdot 3 \cdot 4 \cdot \; 2^4)^2}{1 \cdot 2 \cdot 3 \cdot 4 \cdot 5 \cdot 6 \cdot 7 \cdot 8} \\ \\ &= \frac{(2 \cdot 4 \cdot 6 \cdot 8)^2}{1 \cdot 2 \cdot 3 \cdot 4 \cdot 5 \cdot 6 \cdot 7 \cdot 8} \\ \\ &= \frac{2 \cdot 4 \cdot 6 \cdot 8}{1 \cdot 3 \cdot 5 \cdot 7} \\ \\ &= \frac{8!!}{7!!} \\ \end{align}

Difference of Coefficients

Based on this definition the difference $$a_{k} - a_{k-1}$$ can be calculated:

\begin{align} a_k &= \frac{(2k)!!}{(2k-1)!!} \\ \\ a_k - a_{k-1} &= \frac{(2k)!!}{(2k-1)!!} - \frac{(2k-2))!!}{(2k-3)!!} \\ \\ &= \frac{(2k-2)!!}{(2k-3)!!} \frac{2k}{2k-1} - \frac{(2k-2))!!}{(2k-3)!!} \\ \\ &= \frac{(2k-2)!!}{(2k-3)!!} \cdot \left( \frac{2k}{2k-1} - 1 \right) \\ \\ &= a_{k-1} \cdot \frac{1}{2k-1} \end{align}

Example

$\left \{ a_k \mid k = 0, 1, 2, 3, \cdots \right \} = \left \{ 1, \; \frac{2}{1}, \; \frac{2 \cdot 4}{1 \cdot 3}, \; \frac{2 \cdot 4 \cdot 6}{1 \cdot 3 \cdot 5}, \; \frac{2 \cdot 4 \cdot 6 \cdot 8}{1 \cdot 3 \cdot 5 \cdot 7}, \; \frac{2 \cdot 4 \cdot 6 \cdot 8 \cdot 10}{1 \cdot 3 \cdot 5 \cdot 7 \cdot 9}, \; \cdots \right \}$

For $$k = 4$$ we get:

\begin{align} a_4 - a_3 &= \frac{2 \cdot 4 \cdot 6 \cdot 8}{1 \cdot 3 \cdot 5 \cdot 7} - \frac{2 \cdot 4 \cdot 6}{1 \cdot 3 \cdot 5} \\ \\ &= \frac{2 \cdot 4 \cdot 6}{1 \cdot 3 \cdot 5} \cdot \left(\frac{8}{7} - 1 \right) \\ \\ &= \frac{2 \cdot 4 \cdot 6}{1 \cdot 3 \cdot 5} \cdot \frac{1}{7} \\ \\ &= a_3 \cdot \frac{1}{7} \\ \end{align}

This allows us to find a differential equation for $$y(u)$$:

\begin{align} y(u) \cdot \left( 1 - u^2 \right) &= \sum_{k=0}^{\infty} a_{k} \; u^{2k} \cdot \left( 1 - u^2 \right) \\ \\ &= \sum_{k=0}^{\infty} a_{k} \; u^{2k} - \sum_{k=0}^{\infty} a_{k} \; u^{2k+2} \\ \\ &= \sum_{k=0}^{\infty} a_{k} \; u^{2k} - \sum_{k=1}^{\infty} a_{k-1} \; u^{2k} \\ \\ &= 1 + \sum_{k=1}^{\infty} \left( a_{k} - a_{k-1} \right) \; u^{2k} \\ \\ &= 1 + \sum_{k=1}^{\infty} a_{k-1} \cdot \frac{1}{2k-1} \; u^{2k} \\ \\ \frac{y(u) \cdot \left( 1 - u^2 \right)}{u} &= \frac{1}{u} + \sum_{k=1}^{\infty} a_{k-1} \cdot \frac{1}{2k-1} \; u^{2k-1} \\ \\ \frac{\mathrm{d}}{\mathrm{d} u} \; y(u) \cdot (\frac{1}{u} - u) &= - \frac{1}{u^2} + \sum_{k=1}^{\infty} a_{k-1} \; u^{2k-2} \\ \\ \frac{\mathrm{d}}{\mathrm{d} u} \; y(u) \cdot (\frac{1}{u} - u) &= - \frac{1}{u^2} + \sum_{k=0}^{\infty} a_{k} \; u^{2k} \\ \\ \frac{\mathrm{d}}{\mathrm{d} u} \; y(u) \cdot (\frac{1}{u} - u) &= - \frac{1}{u^2} + y(u) \\ \end{align}

Solution

I'm a bit lazy, so I just post the step-by-step solution that WolframAlpha gave me:

To calculate $$\mu(u)$$ use:

Back Substitution

What's left is using the initial condition $$y(0) = 1$$ to deduce that $$c_1 = 0$$ and replace $$u$$ by:

\begin{align} u &= \frac{\sqrt{x}}{2} \\ \end{align}

Attached File(s) Thumbnail(s)

11-15-2023, 06:10 PM
Post: #12
 Gil Senior Member Posts: 624 Joined: Oct 2019
RE: HP49-50G plotting of sum(x=0 to 0, 1, 2,...10, of x!/(2x)!)
Really lazy!

Amazing and congratulations, Thomas!

I am just baffled.
11-15-2023, 08:08 PM
Post: #13
 Thomas Klemm Senior Member Posts: 2,104 Joined: Dec 2013
RE: HP49-50G plotting of sum(x=0 to 0, 1, 2,...10, of x!/(2x)!)
You didn't ask for it but here's a program for the HP-42S:
Code:
00 { 38-Byte Prgm } 01▸LBL "SERIES" 02 2 03 × 04 X<>Y 05 4 06 ÷ 07 1 08▸LBL 00 09 RCL× ST Y 10 RCL× ST Z 11 DSE ST Z 12 RCL÷ ST Z 13 1 14 + 15 DSE ST Z 16 GTO 00 17 END

Example

This sums the first 20 terms for $$x=1$$:

1 ENTER
20 XEQ "SERIES"

1.73639985872
01-02-2024, 11:36 AM (This post was last modified: 01-02-2024 11:40 AM by Gil.)
Post: #14
 Gil Senior Member Posts: 624 Joined: Oct 2019
RE: HP49-50G plotting of sum(x=0 to 0, 1, 2,...10, of x!/(2x)!)
About DavidM' s answer how to plot the function F1 with the HP50G.

As I said, the procedure is perfect.

Now I tried to plot the FresnelC integral from x=0 to 5.

Here is my program:
\<< 'PPAR' PURGE ERASE FUNCTION -31 CF
\<< 0 X
FOR X '\.S(0.,X,COS(X^2),X)' \->NUM .2
STEP
\>> STEQ 0 5 XRNG 0 1 YRNG DRAX DRAW PICTURE
\>>

But, launching the above program, the final picture of previous function F1 appears.

Then I look at VAR MENU and see that
- EQ contains previous function F1
- PPAR the settings relative to previous function F1.

I delete PPAR EQ and go to the "Y" MENU: now the Y function that was drawn has been duly deleted.

Now I launch again my Fresnel program to draw the function relative to the FresnelC.

But again the final picture of previous function F1 appears, with EQ and PPAR logically with the data of function F1.

My only way to launch the Fresnel function and have ts graph drawn is to work in another directory.

Question:
how can launch my second program 'FresnelC, remaining in my directory — that contains both 'Function1' and 'FresnelC' programs — and get the graph of my new function FresnelC from x=0 to 5?

01-02-2024, 12:10 PM
Post: #15
 Gil Senior Member Posts: 624 Joined: Oct 2019
RE: HP49-50G plotting of sum(x=0 to 0, 1, 2,...10, of x!/(2x)!)
Strangely, it seems to work now...
01-02-2024, 01:57 PM
Post: #16
 DavidM Senior Member Posts: 988 Joined: Dec 2013
RE: HP49-50G plotting of sum(x=0 to 0, 1, 2,...10, of x!/(2x)!)
(01-02-2024 12:10 PM)Gil Wrote:  Strangely, it seems to work now...

It looks like you've set everything up properly. I have no idea why things wouldn't have worked as they should.

Sometimes unexpected results can occur if you've got duplicates of important variables in multiple levels of the current path (PPAR, EQ, etc.). But as far as I can tell, there's nothing wrong with your code as written.

Are you running this on an actual 50g, or on an emulator? Some of the emulators don't maintain port memory for ports >0, and that could also be confusing things if you are storing things in ports (other than 0).
01-02-2024, 02:09 PM (This post was last modified: 01-02-2024 02:15 PM by Gil.)
Post: #17
 Gil Senior Member Posts: 624 Joined: Oct 2019
RE: HP49-50G plotting of sum(x=0 to 0, 1, 2,...10, of x!/(2x)!)
There was first a name collision with my variable name of the first function F1 with an HP49-HP50 command.

I corrected this, but then nothing appeared, if I remember correctly, when running the FresnelC function/program in the same directory as the previous function function F1.

But it worked when FresnelC function/program copied in another directory.

And now, as I mentioned, both seem to work nicely in the same directory.

I saved previously your model program.

Thanks again for your replies.

I use only the EMU48, having lost years ago my real my HP50G calculator.
I bought a new one 2 months ago for 80\$, but I don't use it at all (much to slow, about 100×, in comparison to the phone Android application, and not practical to import data from Internet or export them).
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)