-------------------- -------------------- -------------------- -------

  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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "math.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
double Lag(double* x, double* y, int n, double datx)
{
double result = 0.0;
for (short i = 0; i <= n; i++)
{
double P = 1.0;
for (short j = 0; j <= n; j++)
if (j != i) {
P *=(datx - x[j])/(x[i] - x[j]);
}
result += P * y[i];
}
return result;
}
double f(double x){return exp(fabs(x+x*x*x*x));}
double a=-1, b=1;
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Label1->Caption ="Cтепень интерполяционного многочлена не должна превышать 50";
Label2->Caption ="";
Series7->Clear();
Series2->Clear();
Series5->Clear();
Series6->Clear();
double n=5;
double yp[10000];
double x[10000];
double y[10000];
double xf[10000];
double yf[10000];
double yl[10000];
double ym[10000];
double m=0;
double mm=0;
double b=0; int v=0;
for (double i = 0; v<199; i=i+0.01) {
double a=-1+i, b=a+0.01;
v=v+1;
if (n>500) {n=500;}
if (n==0) {n=1; Label1->Caption = "Cтепень интерполяционного многочлена изменена на 1";}
double h;
if (n!=0) {h=(b-a)/n;}
for (int i = 0; i <=n; i++) {
x[i]=a+h*i;
y[i]=f(x[i]);
}
h=(b-a)/(n*100) ;
for (int i = 0; i <=n*100; i++) {
xf[i]=a+h*i;
yf[i]=f(xf[i]);
yl[i]=Lag(x,y,n,xf[i]);
yp[i]=fabs(yf[i]-yl[i]);
if(yp[i] > m) {m = yp[i];}
Series1->AddXY(xf[i], yf[i],"", clBlue);
Series7->AddXY(xf[i], yl[i],"", clGreen);
}
int k=100*i;
ym[k]=m;
if(ym[k] > mm) {mm = yp[k];}
}
Label2->Caption = mm;
double p=0.0000000001;
Series3->AddXY(15, m,"", clGreen);
if (m<p) {
Label3->Caption = "Подходящая степень интерполяции";
} else Label3->Caption="";
}
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Label1->Caption ="Cтепень интерполяционного многочлена не должна превышать 50";
Label2->Caption ="";
Series7->Clear();
double n = Edit1->Text.ToInt();
double yp[10000];
double x[10000];
double y[10000];
double xf[10000];
double yf[10000];
double yl[10000];
double m=0;
if (n>500) {n=500;}
if (n==0) {n=1; Label1->Caption = "Cтепень интерполяционного многочлена изменена на 1";}
double h;
if (n!=0) {h=(b-a)/n;}
for (int i = 0; i <=n; i++) {
x[i]=a+h*i;
y[i]=f(x[i]);
}
h=(b-a)/(n*100) ;
for (int i = 0; i <=n*100; i++) {
xf[i]=a+h*i;
yf[i]=f(xf[i]);
yl[i]=Lag(x,y,n,xf[i]);
yp[i]=fabs(yf[i]-yl[i]);
if(yp[i] > m) {m = yp[i];}
Series1->AddXY(xf[i], yf[i],"", clBlue);
if (n==2) {Series2->AddXY(xf[i], yl[i],"", clGreen);}
if (n==6) {Series5->AddXY(xf[i], yl[i],"", clGreen);}
if (n==10) {Series6->AddXY(xf[i], yl[i],"", clGreen);}
}
Label2->Caption = m;
Series3->AddXY(n, m,"", clGreen);
if (m<0.0001) {
Label3->Caption = "Подходящая степень интерполяции";
} else Label3->Caption="";
}
//---------------------------------------------------------------------------