L
L
leadrig2019-10-27 22:30:55
Mathematics
leadrig, 2019-10-27 22:30:55

Can you explain how this code (recursive formula) works?

9ZOga7Ry97Q.jpg
Number 4.
Here is the code:

program Project1;

{$APPTYPE CONSOLE}

uses
SysUtils;

var
x, eps, R, S, St, Ea, Eo: real;
n, k: integer;

begin
writeln('Ведите x, eps, k');
readln(x, eps, k);
writeln;
n:=0;
S:=1+(x*x)/2;
R:=1*(x*x)/2*2;
St:=sqrt(1+x);
while abs(R)>=eps do
begin
n:=n+1;
R:=(-1)*R*x*(2*n-1)/(2*n+2);
S:=S+R;
end;
Ea:=(Abs(sqrt(1+x)-S));
Eo:=(Abs((sqrt(1+x)-S)/sqrt(1+x)));
writeln('S=', S:k+3:k);
writeln('R=', R:k+3:k);
writeln('n=', n);
writeln('St=', St:k+3:k);
writeln('Ea=', Ea:k+3:k);
writeln('Eo=', Eo:k+3:k,'%');
readln;
{ TODO -oUser -cConsole Main : Insert code here }
end.

I don't understand the math here.
I can make a similar program, but using conditional statements. Here it all works with one formula.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question