https://github.com/n1ghtf1re/additional-task-for-laboratory-work-3
Lab №3. Iterative cycles - an additional task
https://github.com/n1ghtf1re/additional-task-for-laboratory-work-3
Last synced: 6 months ago
JSON representation
Lab №3. Iterative cycles - an additional task
- Host: GitHub
- URL: https://github.com/n1ghtf1re/additional-task-for-laboratory-work-3
- Owner: N1ghtF1re
- Created: 2017-10-15T18:51:53.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-03T06:17:39.000Z (almost 8 years ago)
- Last Synced: 2025-02-19T05:52:03.157Z (8 months ago)
- Language: Pascal
- Homepage:
- Size: 37.1 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Lab №3. Iterative cycles - an additional task
--------------------
***
#### Task:
>The program calculates the integral Fresnel sin for large cases of the argument, using the asymptotic expansion
**Language**: Delphi
**Algorithm scheme**:

**Code:**
``` pascal
program lab3_additional;{$APPTYPE CONSOLE}
uses
math;
var x,u,e,RealX,s,CoefCos,CoefSin:Real;
b:integer;
UStr:string;
Coef:ShortInt;function getTeylorSin(x:Real):Real;
var CurrTerm, eps, Prev, Curr: real;
n:Byte;
begin
eps:=1;
CurrTerm:=x;
n:=1;
Curr:=x;
while(eps > e) do
begin
CurrTerm:=CurrTerm*(-1)*x*x/(2*n*(2*n+1));
Prev:=Curr;
Curr:=Curr+CurrTerm;
eps:=Abs(Prev-Curr);
Inc(n);
end;
getTeylorSin:=Curr;
end;function getTeylorCos(x:Real):Real;
var CurrTerm, eps, Prev, Curr: real;
n:Byte;
begin
eps:=1;
CurrTerm:=1;
n:=1;
curr:=1;
while(eps > e) do
begin
CurrTerm:=CurrTerm*(-1)*x*x/(2*n*(2*n-1));
Prev:=Curr;
Curr:=Curr+CurrTerm;
eps:=Abs(Prev-Curr);
Inc(n);
end;
getTeylorCos:=Curr;
end;procedure getRows(x:Real);
var CurrTerm, epsSin,epsCos, CCoefPrev,SCoefPrev, TwoX: real;
n:Integer;
isEndCos, isEndSin:Boolean;
begin
epsSin:=1;
epsCos:=1;
CurrTerm:=1;
coefsin:=1;
coefcos:=1;
n:=1;
TwoX:=4*x*x;
isEndCos:= false;
isEndSin:=false;
while(isEndCos and isEndSin) do begin
CCoefPrev:= CoefCos;
SCoefPrev:= CoefSin;
CurrTerm:=CurrTerm*(-1)*n*(n+2)/TwoX;
if (isEndCos = false) then
begin
CoefCos:=CoefCos+Currterm;
epsCos:= Abs(abs(CoefCos)-abs(CCoefPrev));
end;
if (isEndSin = False) then
begin
CoefSin:=CoefSin+CurrTerm*(n+4);
epsSin:= Abs(CoefSin-SCoefPrev);
end;
if(epsSin >= e) then
isEndSin:=true;if (epsCos >= e) then
isEndCos:=true;inc(n,4);
end;
end;begin
repeat
Writeln('Please, enter the desired accuracy (e < 1)');
write('e = ');
Readln(e);
until(e < 1);
repeat
Writeln(#10#13,'Please, enter value of u (u > 3). To exit enter "Exit"',#10#13);
write('u = ');
Readln(UStr);
Val(UStr,u,b);
if (Abs(u) < 3) then
Writeln(#10#13#10#13,'The entered value of x is too small',#10#13);
if ((b = 0) and (Abs(Trunc(u*100)/100) > 3)) then
begin
if(u >= 0) then
Coef:=1
else
Coef:=-1;x:=Pi*u*u/2;
RealX:=x;
x:= x - Trunc(x/(2*pi))*2*pi; // reduce x to the first quarter
// ----- Integral Sin ------ //
getRows(RealX);
s:=coef*1/2-getTeylorCos(x)*CoefCos/Sqrt(2*pi*RealX) - getTeylorSin(x)*CoefSin/(Sqrt(2*pi*RealX)*2*x);
Writeln('S(u) = ', s:0:4);
end;
until(b > 0);
end.```