The formula given in the title is used for approximating the roots of non-perfect square numbers.
$${\sqrt x}=\frac{x + y}{2\sqrt y}$$
Here, 'x' is the number you want the root for and 'y' is the nearest perfect square.
For example:
- If x is 79, then y would come out to be 81
- if x is 118, then y would come out to be 121
What I wish to find out is, how much the roots found using this formula differ from the actual roots.
For example:
- Taking x = 79 and y = 81. Substituting that into equation we get ${\sqrt x}$ = 8.888. Which is exactly the value you get using a calculator 8.888
- Taking x =118 and y = 121. Substituiting that into the equation we get ${\sqrt x}$ = 10.863. Which differs about 0.001 from the value you get using a calculator which is 10.862
My problem is, I wish to plot a graph which would take the root on the x-axis and plot the difference on the y-axis . I do not know of any program which can find the nearest perfect square as well as plot the graph.
manually finding the values and plotting them tells me the graph gives a saw tooth pattern where the highest difference exponentially decays as the values of x increase.
I tried doing this in desmos but as you could guess there is no way to find the 'y' for the different values of 'x'.
P.S. I have no idea what tags to use in this so I am sorry for any mistake
In gnuplot, you can define function with tests. Recall that the function
intreturns the integer part of its argument, truncated toward zero. Then,y(x)should be eitherint(sqrt(x))**2or(int(sqrt(x))+1)**2, whichever is the closest (in gnuplot,x**2meansx*x). Then you could defineThen your plot can be obtained with
Second method, which should work with all plotter program. Let $n=\lfloor\sqrt x\rfloor$ the integer part of $\sqrt x$. Then $y$ should be either $n^2$ or $(n+1)^2$. It should be $(n+1)^2$ if and only if $$ x-n^2 \ge (n+1)^2-x$$ after rearranging this, this is equivalent to $$(n+\tfrac12)^2\le x-\tfrac14$$ I am going to assume for simplicity that $x>\tfrac14$. For the general case, you could replace in what follows $x-\tfrac14$ by $\max(0,x-\tfrac14)$. Then the condition is equivalent to $$ n+1 \le \sqrt{x-\tfrac14}+\tfrac12$$ Then, clearly, $$ y(x)= \Big\lfloor \sqrt{x-\tfrac14}+\tfrac12\Big\rfloor^2 $$ or, as a gnuplot command,