Lab 03

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
//---------------------------------------------------------------------------
#include<math.h>
#include <vcl.h>
#pragma hdrstop
#include "Mybible.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
for (int i=1;i<=k;i++)
{
SG1->Cells[0][i]="строка №"+IntToStr(i);
SG1->Cells[i][0]="столбец №"+IntToStr(i);
SG2->Cells[0][i-1]="Эл-т №"+IntToStr(i); }
}
//---------------------------------------------------------------------------
matr a; vect x;
void __fastcall TForm1::Button4Click(TObject *Sender){ Close();}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
int i,j;
for (i=0;i<=k;i++)
for (j=0;j<=k;j++)
SG1->Cells[j+1][i+1]=" ";
for (i=0;i<=k;i++)
SG2->Cells[1][i]="";
Edit1->Text="";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button5Click(TObject *Sender)
{
double g=0;
g=funG(x);
Edit1->Text=FormatFloat("0.000",g);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
elemVect(a,x);
for (int i=0; i<k;i++)
SG2->Cells[1][i]=FormatFloat("0.000",x[i]);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
elemMatr (a);
int i,j;
for (i=0;i<k;i++)
for (j=0;j<k;j++)
SG1->Cells[j+1][i+1]=FormatFloat("0.000", a[i][j]);
Button2->Visible=1;
Button3->Visible=1;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#ifndef MybibleH
#define MybibleH
//---------------------------------------------------------------------------
const int k=6;
typedef double matr[k][k];
typedef double vect[k];
void elemMatr(matr c);
void elemVect(matr c, vect v);
double funG(vect c);
void elemMatr (matr c){
int i, j;
for(i=0;i<k; i++)
for(j=0;j<k; j++)
c[i][j]=sqrt(i+5)*2*pow((j+1),-2)-abs(i+j-4);
}
void elemVect (matr c, vect v)
{
int i, j;
for(i=0;i<k;i++)
{
v[i]=0;
double b=1;
for (j=0;j<k;j++){
if(c[i][j]>0){
b*=c[i][j];
v[i]=b;
}
}
}
}
double funG(vect x)
{
int i,j; double a, g;
g=0;
for (i=0;i<4;i++)
{
a=1;
for (j=0;j<=i;j++) a*=x[j]+log(x[j]);
g+=x[j]/a;
}
return g;
}
#endif