< -->

Program _String;
{:::::: Программа, изображающая частичную сумму рядов Фурье :::::}
{$N+}
Uses Graph, CRT;
const
     Sx : Extended = 63.0;
     Sy : Extended = 30.0;
     PiGra : Extended = 4.0;
var
   D, R, e, YTx : Integer;
   x, y, Pi_, _Pi_, t : Extended;
   i : Integer;
   VisPg, ActPg : Word;
{-----------------------}
Procedure BuildScreen;
var
   i : Byte;
begin
  ActPg := ActPg + VisPg;
  VisPg := ActPg - VisPg;
  ActPg := ActPg - VisPg;
  SetActivePage(ActPg);
  SetVisualPage(VisPg);
  SetBkColor(Black);
  ClearViewPort;
  SetColor(DarkGray);
  MoveTo(0, 240);
  LineTo(640, 240);
  LineTo(630, 238);
  LineTo(630, 242);
  LineTo(640, 240);
  MoveTo(320, 480);
  LineTo(320, 0);
  LineTo(318, 10);
  LineTo(322, 10);
  LineTo(320,0);
  SetColor(LightGray);
  for i := 1 to 32 do Line(i*20, 239, i*20, 241);
  for i := 1 to 24 do Line(319, i*20, 321, i*20);
  SetColor(Brown);
  OutTextXY(324, 230, '0');
  OutTextXY(632, 230, 'x');
  OutTextXY(324, 3, 'y');
end;
Function f(x:Extended):Extended;
begin
  if x<0 then f := -Pi_ else
     if x>0 then f := Pi_
        else f := 0;  {Signum}
 { f := x;{////}
end;
{=======+++ n-е члены ряда +++==============}
Function Series(k, x : Extended) : Extended;
var
   a : Extended;
begin
 a :=3.5798;
 { Series := 2*cos((2*k+1)*x); {delta-функция }
 { Series := -4.0/(Pi_*sqr(2*k+1))*cos((2*k+1)*x); { 0^ /\/\/\/\/\ Надо : -Pi_/2.0 в FourierSumma}
 { Series := 4*sin((2*k+1)*x)/(2*k+1);{ (Меандр - Signum "-_-_-_-_")}
 { Series := 2.0*cos(Pi_*(k+1))*sin(k*x)/k; { ///%//// f(x)=x период. 2*Pi, -Pi..Pi}
 { Series := -2.0*sin(k*x)/k; { ///|//// f(x)=x период. 2*Pi, -0..2*Pi}
 { Series := sin(a*Pi_)*2*k*sin(k*x)/(Pi_*(a*a-k*k)); {sin(ax)}
 { Series := cos(Pi_*k)+k*sin(k*x)/(k*k+1); {x- функция}
  Series := -k*(cos(k*x)-sin(k*x))/(k*k+1); {}
end;
{=====+++ Частичная сумма ряда с n1-ого по n2-ый член + свободный член +++=====}
Function FourierSumma(n1, n2 : Longint; x : Extended) : Extended;
var
   S : Extended;
   i : Longint;
begin
  S := 0;
  for i := n1 to n2 do
  S := S + Series(1.0*i, x);
  FourierSumma:=S{-Pi_/2.0};
end;
Function U(t, x : Extended; k1, k2 : Longint):Extended;
var
   S : Extended;
   i : Longint;
begin
  S := 0;
  for i := k1 to k2 do
  S := S + cos(Pi_*i)*cos(Pi_*i*t)*sin(Pi_*i*x)*2/(Pi_*i);
{  S := S + cos(Pi_*t)*sin(Pi_*x)+sin(2*Pi_*t)*sin(2*Pi_*x)/2/Pi_;}
  U := S;
end;
begin
  D:=Detect;
  InitGraph(D,R,'');
  e:=GraphResult;
  if e <> 0 then
    begin
      WriteLn('Ошибка графики(', e, '):');
      WriteLn(GraphErrorMsg(e));
      Halt;
    end;
  Pi_ := Pi;
  _Pi_ := Pi_*PiGra;
  ActPg := 0;
  VisPg := 0;
  t := 0;
  While t<30 do
  begin
  x := -_Pi_;
  BuildScreen;
  repeat
   y := U(t, x/10, 1, 50);
   x := x + 0.01;
   PutPixel(Trunc({320.0+}x*Sx), Trunc(240.0-y*Sy), Yellow);
  until  (x>_Pi_) or KeyPressed;
  t := t + 0.1;
  if keyPressed then Break;
  end;
  ReadKey;
  CloseGraph;
end.

Назад 3