Версия для печати темы

Нажмите сюда для просмотра этой темы в обычном формате

Форум «Всё о Паскале» _ Делфи _ Очень прошу, помогите найти ошибки в коде!.Ряд Фурье(Pascal)

Автор: iryna 18.03.2018 3:16


Это код оконного режима Ряду Фурье. Этот код дал преподаватель и намеренно сделал в нем небольшие глупые ошибки. Программа не работает((
Это очень важно, прошу помогите !!!

unit Unit2;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Samples.Spin, Vcl.StdCtrls,
Vcl.ExtCtrls;

type
Vector = array [0..1000] of Real; // для створення масивів із координатами графіків
Vec = array [0..50] of Real; // для створення масивів із коефіцієнтами ряду Фур’є
TForm2 = class(TForm)
Image1: TImage;
GroupBox1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
SpinEdit1: TSpinEdit;
SpinEdit2: TSpinEdit;
SpinEdit3: TSpinEdit;
SpinEdit4: TSpinEdit;
Button2: TButton;
Button3: TButton;
procedure Button2Click(Sender: TObject);

private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;
Xe, Ye : Vector; // Масиви для зберігання координат нашої періодичної функції
Xg, Yg : Vector; // Масиви для зберігання координат протабульованого ряду Фур'є
a, b, c : Vec; // Масиви для зберігання коефіцієнтів ряду Фур'є
Ne, Ngr, Ng : Integer; // Ne = Ngr кількість точок обох графіків
al, bl, Tp : Real; // Область визначення функції та її період : Tp = bl – al

implementation

{$R *.dfm}


Function f(x : Real) : Real; // Опис нашої періодичної функції
Begin
Tp := bl - al;
if x < TP / 2 then
f:= 2 else
if(x >= TP / 2) and (x < 3 * TP / 4) then
f := 4 * (TP - 2 * x) / TP
else
f := 8 * (x - TP) / TP;
end;
Procedure TabF(var Xe: Vector; var Ye: Vector);// Процедура табулювання періодичної функції
Var h : Real;
i : Integer;
Begin
h := (bl - al) / Ne;
Xe[0]:= al;
For i := 0 to Ne - 1 do
Begin
Ye[i] := f(Xe[i]) ;
Xe[i+1] := Xe[i] + h;
End;
End;
procedure TForm2.Button2Click(Sender: TObject);
begin

begin
Self.Close;
end;
end;

end.
// Процедура побудови і табулювання ряду Фур’є згідно з алгоритмом, що є на рис. 4.
Procedure Furje(Xe, Ye : Vector; Ne : Integer; var Yg : Vector);
Var i, k : Integer;
w, KOM, S, G, D : Real;
Begin
Ng := StrToInt(Form1.Edit2.text); // Вводимо кількість гармонік
TP := bl - al; // TP – період нашої функції
// Обчислення коефіцієнтів ряду Фур'є
w := 2 * Pi / TP;
For k := 1 to Ng do
Begin
KOM := k * w;
G := 0.0;
D := 0.0;
For i :=1 to Ne do
Begin
S := KOM * Xe[i];
G := G + Ye[i] * Cos(S);
D := D + Ye[i] * Sin(S);
End;
a[k] := 2 * G / Ne;
b[k] := 2 * D / Ne;
c[k] := Sqrt(Sqr(a[k]) + Sqr(b[k]));
End;
a[0] := 0.0;
For i := 1 to Ne do
a[0] := a[0] + Ye[i];
a[0] := a[0] / Ne;
For i := 0 to Ne - 1 do // Побудова і табулювання суми ряду Фур’є
Begin
S := 0;
D := Xe[i] * w;
For k:=1 to Ng do
Begin
KOM := k * D;
S := S + b[k] * Sin(KOM) + a[k] * Cos(KOM);
End;
Yg[i] := a[0] + S;
End;
End;
end;
procedure TForm2.Button3Click(Sender: TObject);
begin
Procedure TForm1.Button1Click(Sender : TObject);
Var p,zx,zy,ay,bx,krx,kry,xx,yy,Gx,Gy : Real;
i,j,krokx,kroky,drv,drm,visx,visy : Integer;
l:integer;
minYg,maxYg,maxx,maxy,minx,miny,kx,ky:real;
// Процедура візуалізації гармонік
Procedure Garm(Ng : Integer; c:Vec);
Var i , Krokx, x : Integer;
MaxC, Ky, W : Real;
Begin
Krokx := (Image1.ClientWidth - 2 * L) div Ng;
MaxC := c[1];
For I := 2 to Ng do
If c[i] > MaxC then MaxC := c[i];
Ky := (Image1.ClientHeight div 2) / MaxC;
With Image1.Canvas do
Begin
Pen.Color := clHighlight;
Pen.Width := 2;
MoveTo(L, L + 20 );
LineTo(L + 10, L + 10);
LineTo(L + 20, L + 20);
MoveTo(L + 10, L + 10);
LineTo(L + 10, Image1.ClientHeight - 50);
LineTo(Image1.ClientWidth-20, Image1.ClientHeight-50);
MoveTo(Image1.ClientWidth-40, Image1.ClientHeight-60);
LineTo(Image1.ClientWidth-20, Image1.ClientHeight-50);
LineTo(Image1.ClientWidth-40, Image1.ClientHeight-40);
TextOut(L - 2, L ,'C');
TextOut(ClientWidth - 50, ClientHeight - 25 ,'W');
Pen.Color := clFuchsia;
Pen.Width := 2;
x := KrokX + 20;
w := 2 * Pi /(bl - al);
For i:= 1 to Ng do
Begin
MoveTo(Round(x)+3,Image1.ClientHeight-50);
LineTo(Round(x)+3,Image1.ClientHeight-50-Round(ky*c[i]));
TextOut(round(x),Image1.ClientHeight - Round(ky*c[i])-65, FloatToStrF(x,ffGeneral,0,0));
Ellipse(round(x),Image1.ClientHeight-53,round(x)+5,Image1.ClientHeight-48);
end;

end. wub.gif

Автор: lower price on finasteride cambe 4.11.2021 17:23

Buy Tamoxifen For Men

Автор: does gabapentin cause weight gai 10.12.2021 8:06

Levitra Neu

Автор: nishaknapp 16.01.2023 6:27

Why not settling on games that is fun and at the same time your earning. Well it'll make suspense because the game is well but dude just try it and it gave me hope while pandemic is real rn. https://itsmartech.com/5-practical-ways-to-become-a-smart-casino-player/

Добавлено через 1 мин.
Why not settling on games that is fun and at the same time your earning. Well it'll make suspense because the game is well but dude just try it and it gave me hope while pandemic is real rn. https://talkeo.net/why-are-online-casinos-popular-to-newbie-players/