![]() |
|
|
Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
![]() |
|
Опции темы | Поиск в этой теме | Опции просмотра |
|
#1
|
|||
|
|||
![]() Требуется расчитать и оптимизировать электрическую цепь, состоящую из 6 ветвей. Для проверки хода расчета вывожу Хс. считаю процедурой:
Код:
for i:=1 to 6 do if C[i]=0 then XC[i]:=0 else XC[i]:=(1/(pi*100*C[i])); где С-емкость катушки, i-порядковый номер ветви, содержащей катушку. Хс упорно равно 0 при любом значении С. наверняка обнуляет при вводе данных, а вот где, как и почему найти не могу.Толи класс создаю не правильно... исходный код : Код:
unit ClTypes; interface uses SysUtils; type TGenRes=array[1..6]of real;//общее сопротивление участкка TXL=array[1..6] of real; TXC=array[1..6] of real; TZRes=array [1..6] of real; TAngle=array [1..6] of real; TBranch=class Cur:array [1..6] of real;//ток Voltage: array [1..6] of real; PB:real;//баланс мощности procedure XLCalc(i,n:byte);//считаем xc procedure XCCalc(i,n:byte); procedure ZResCalc(i,n:byte); procedure AngleCalc(i,n:byte); procedure CalcCur(i,n:byte); procedure Datainp; procedure PowBal(i,n:byte); public Zres:TZRes; Angle:Tangle; Xl:TXl; Xc:TXc; L: array[1..6] of real; C: array [1..6] of real; R: array [1..6]of real; end; TOptArea=class(TBranch) procedure CalcOptArea(i,n:byte;ResAr,Volt:real); end; var a:byte; k:byte; Branch:TBranch; t:real; implementation uses main,calc; { TBranch } procedure TBranch.AngleCalc(i,n:byte); begin Branch:=TBranch.Create; n:=6; for i:=1 to n do if R[i]=0 then if((XL[i]-XC[i])>0) then Angle[i]:=pi/2 else if((XL[i]-XC[i])>0) then Angle[i]:=-pi/2 else Angle[i]:=arctan((xl[i]-xc[i])/r[i]); end; {procedure TBranch.CalcCur(i,n:byte); begin Gauss:=TGauss.Create; Gauss.CalcEqvSyst(i,j,k,n); Cur[6]:=EqvSyst.Ik[1]; Cur[2]:=EqvSyst.Ik[2]; Cur[3]:=EqvSyst.Ik[1]-EqvSyst.Ik[3]; Cur[4]:=EqvSyst.Ik[3]-EqvSyst.Ik[2]; Cur[5]:=EqvSyst.Ik[1]-EqvSyst.Ik[2]; Cur[1]:=EqvSyst.Ik[3]; end;} procedure TBranch.Datainp;//Присваиваем значения С begin Branch.C[1]:=0; Branch.C[2]:=StrToFloat(Form1.StringGrid1.Cells[3,1])*0.000001; Branch.C[3]:=0; Branch.C[4]:=0; Branch.C[5]:=StrToFloat(Form1.StringGrid1.Cells[2,1])*0.000001; Branch.C[6]:=StrToFloat(Form1.StringGrid1.Cells[1,1])*0.000001; Branch.L[1]:=StrToFloat(Form1.StringGrid1.Cells[4,1])*0.001; Branch.L[2]:=StrToFloat(Form1.StringGrid1.Cells[5,1])*0.001; Branch.L[3]:=0; Branch.L[4]:=0; Branch.L[5]:=0; Branch.L[6]:=0; Branch.R[1]:=StrToFloat(Form1.StringGrid1.Cells[6,1]); Branch.R[2]:=StrToFloat(Form1.StringGrid1.Cells[7,1]); Branch.R[3]:=StrToFloat(Form1.StringGrid1.Cells[8,1]); Branch.R[4]:=StrToFloat(Form1.StringGrid1.Cells[9,1]); Branch.R[5]:=0; Branch.R[6]:=0; end; procedure TBranch.PowBal(i,n:byte); begin Gauss:=TGauss.Create; Gauss.Assignment(i,n); Branch.Create; Branch.CalcCur(i,n); Gauss.CalcEqvSyst(i,j,k,n); n:=6; For i:=1 to n do PB:=ZRes[i]*sqr(Cur[i]); PB:=PB+ZRes[i+1]*sqr(Cur[i+1]); end; procedure TBranch.XCCalc(i,n:byte);//считаем С begin Branch.Datainp; for i:=1 to 6 do if C[i]=0 then XC[i]:=0 else XC[i]:=(1/(pi*100*C[i])); end; procedure TBranch.XLCalc(i,n:byte); begin n:=6; for i:=1 to n do XL[i]:=(pi*100*L[i]); end; procedure TBranch.ZResCalc(i,n:byte); begin Branch.Datainp; Branch.XLCalc(i,n); Branch.XCCalc(i,n); for i:=1 to 6 do ZRes[i]:=sqrt(sqr(R[i])+sqr(Xl[i]-Xc[i])); end; { TOptArea } procedure TOptArea.CalcOptArea(i,n:byte;ResAr,Volt: real); var AngArc:real; begin ResAr:=sqrt(sqr(R[2])+sqr(Xl[2])); AngArc:=arctan((xl[2]/r[k])); Volt:=ResAr*Cur[2]*sin((100*pi*t)+AngArc); end; end. Код:
unit Main; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Menus, Buttons, StdCtrls, Grids, jpeg, ExtCtrls,Calc,ClTypes; type TForm1 = class(TForm) GroupBox1: TGroupBox; Image1: TImage; GroupBox2: TGroupBox; Label1: TLabel; Label2: TLabel; Label8: TLabel; StringGrid1: TStringGrid; StringGrid2: TStringGrid; Button1: TButton; GroupBox3: TGroupBox; Label6: TLabel; Label7: TLabel; Label9: TLabel; StringGrid3: TStringGrid; Button2: TButton; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; GroupBox4: TGroupBox; Label3: TLabel; Label4: TLabel; Label5: TLabel; BitBtn1: TBitBtn; MainMenu1: TMainMenu; N1: TMenuItem; N6: TMenuItem; N7: TMenuItem; N8: TMenuItem; N2: TMenuItem; N3: TMenuItem; N4: TMenuItem; N5: TMenuItem; Label10: TLabel; procedure IntFace(Sender: TObject); procedure N8Click(Sender: TObject); procedure BitBtn1Click(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; I,j,k,n:byte; EqvSyst:TEqvSyst; implementation {$R *.dfm} procedure TForm1.IntFace(Sender: TObject); begin StringGrid1.Cols[0].Text:='U(t)B'; StringGrid1.Cols[1].Text:='C1 мкФ'; StringGrid1.Cols[2].Text:='C2 мкФ'; StringGrid1.Cols[3].Text:='C3 мкФ'; StringGrid1.Cols[4].Text:='L1 мГн'; StringGrid1.Cols[5].Text:='L2 мГн'; StringGrid1.Cols[6].Text:='R1 Ом'; StringGrid1.Cols[7].Text:='R2 Ом'; StringGrid1.Cols[8].Text:='R3 Ом'; StringGrid1.Cols[9].Text:='R4 Ом'; StringGrid2.Cells[0,0]:='Номер ветви'; StringGrid2.Cells[1,0]:='Сила тока А'; StringGrid2.Cells[2,0]:='Cопротивление Ом'; StringGrid2.Cells[3,0]:='Сдвиг фаз рад'; StringGrid2.Cells[0,1]:='1'; StringGrid2.Cells[0,2]:='2'; StringGrid2.Cells[0,3]:='3'; StringGrid2.Cells[0,4]:='4'; StringGrid2.Cells[0,5]:='5'; StringGrid2.Cells[0,6]:='6'; StringGrid3.Cells[0,0]:='Итерация'; StringGrid3.Cells[1,0]:='R3 Ом'; StringGrid3.Cells[2,0]:='C2 мкФ'; StringGrid3.Cells[3,0]:='Q'; StringGrid3.Cells[0,1]:='C1'; StringGrid3.Cells[0,2]:='C2'; StringGrid1.Cells[0,1]:='100'; StringGrid1.Cells[1,1]:='100'; StringGrid1.Cells[2,1]:='50'; StringGrid1.Cells[3,1]:='200'; StringGrid1.Cells[4,1]:='1'; StringGrid1.Cells[5,1]:='5'; StringGrid1.Cells[6,1]:='500'; StringGrid1.Cells[7,1]:='1000'; StringGrid1.Cells[8,1]:='500'; StringGrid1.Cells[9,1]:='100'; end; procedure TForm1.N8Click(Sender: TObject); begin Close; end; procedure TForm1.BitBtn1Click(Sender: TObject); begin Close; end; procedure TForm1.Button1Click(Sender: TObject);//выводим Xc по кнопке begin Branch:=TBranch.Create; Branch.Datainp; Branch.XLCalc(i,n); {Form1.Label10.Caption:=FloatToStr(Branch.PB); } Form1.StringGrid2.Cells[1,1]:=FloatToStr(Branch.Xc[1]); end; end. Снится уже ошибка( Последний раз редактировалось Hippie, 09.01.2010 в 15:14. |
#2
|
||||
|
||||
![]() Попробуйте пошагово выполнить вашу прогу (нажатие F8) при этом следя за состоянием переменных. Выручяло не раз в сложных программах.
|
#3
|
|||
|
|||
![]() Спасибо, разобралась)
Протупила и несколько раз создала форму=> обнуляла сама. |