User:Egm6341.s10.team4.anandankala/HW5-9

Given

 * {| style="width:70%" border="0" align="center"




 * Given below is the Kessler's code


 * }.
 * }.

Find

 * {| style="width:85%" border="0" align="center"

Use (p2,p3),(p4,p5)(p6,p7) to understand the Kessler's code                       $$\displaystyle $$
 * }.
 * }.

Solution

 * {| style="width:85%" border="0" align="center"

The above code has been used to compute the coefficients p(2k) and the constants c(k) where k varies from 1 to n.

In the above code a function fracsum has been defined and called accordingly in order to compute c(k) and p(2k).

The various commands used in the code are gcd, lcm and round. Gcd is used to find the greatest common divisor between two numbers, lcm is used to find the least common multiple of the two numbers and round is used to round off a number to its nearest intezer.

We know that $$\displaystyle p_2(t)= -\frac {t^2}{2!} + \frac {1}{6} $$

$$\displaystyle $$
 * }.
 * }.


 * {| style="width:70%" border="0" align="center"

$$\displaystyle \Rightarrow p_2(1)= -\frac {1}{2!} + \frac {1}{6}= -\frac {1}{3}$$ $$\displaystyle $$
 * }.
 * }.


 * {| style="width:76%" border="0" align="center"

$$\displaystyle p_4(t)= -\frac {t^4}{24} + \frac {t^2}{12} - \frac {7}{360}$$ $$\displaystyle $$
 * }.
 * }.


 * {| style="width:70%" border="0" align="center"

$$\displaystyle \Rightarrow p_4(1)= -\frac {1}{24} + \frac {1}{12} - \frac {7}{360}= \frac {1}{45}$$ $$\displaystyle $$
 * }.
 * }.


 * {| style="width:70%" border="0" align="center"

$$\displaystyle c1=-1, c3=\frac{1}{6}, c5=\frac{-7}{360}. $$ $$\displaystyle $$
 * }.
 * }.


 * {| style="width:85%" border="0" align="center"

In the code, the value of c1 is taken to be -1. The value of k ranges from 1 to n, the value of n being user defined. Considering the case where k=1, we get the value of c3 and p2(1).

We have $$\displaystyle f=f\cdot g\cdot (g+1)$$ and cn=-1, cd=1.

The initial values of f and g are 1,2. The final value of f is equal to 6.

The variables for the function fracsum are $$\displaystyle(-1\cdot cn)$$ and $$\displaystyle(cd\cdot f)$$, which give the new values of c after every iteration.

The array size of the input variables for the function increases by a unit size after every iteration.

The funtion inputs in the first iteration are (1,6) which are equivalent to (n,d). The function returns the output values of these as (1,6).

The cn array has now been updated to [-1 1] and the cd array to [1,6], where cn and cd are the numerator and denominator of constant c(k+2).

To compute the value of p2(1), the following steps are done in the program. f array has been changed to [f;1] and g array to [2+g(1);g]. For k=1, we get it as f=[6 1] and g= [4 2]. Now these input variables are returned to the function as $$\displaystyle(g-1)\cdot cn $$and $$\displaystyle f\cdot cd$$ where cn= [-1 1] and cd= [1 6].

In this case we get arrays with two elements each and the commands gcd and lcm are implemented independently on each of those elements. we get the values of newpn and newpd as -1 and 3, where pn and pd are the numerator and denominator of p2k(1). We get p=[pn pd]=[-1 3]

$$\displaystyle $$
 * }.
 * }.


 * {| style="width:85%" border="0" align="center"



In the next iteration the value of k is increased to 2.

$$\displaystyle f=f\cdot g\cdot (g+1)$$. We get f= [120 6], cn= [-1 1] and cd= [1 6].

From the function, we get the values of newcn and newcd as -7 and 360.

For computing p4(1), f is again changed to [120 6 1] and g to [6 4 2]. The function is called again with input variables as $$\displaystyle(g-1)\cdot cn $$and $$\displaystyle f\cdot cd$$.

We get the values of newpn and newpd as 1 and 45. pn=[-1 1] and pd=[3 45].

similar cycle is continued for all the higher iterations and we get the higher p and c.

$$\displaystyle $$
 * }.
 * }.