void ermit_5(double *a, double zl, double zp, int p) {
double h, x1;
h = (zp - zl) / 2;
x1 = (zp + zl) / 2;
a[3] = ((h * h * (fp(zp, p) - fp(zl, p))) / (f(zp, p) - f(zl, p) - h * (fp(
zp, p) + fp(zl, p)))) - x1;
a[2] = ((fp(zp, p) - fp(zl, p)) * (((x1 + a[3]) * (x1 + a[3]) - h * h)
* ((x1 + a[3]) * (x1 + a[3]) - h * h))) / (4* h * (x1 + a[3]));
a[0] = fp(zl, p) + a[2] / ((x1 + a[3] - h) * (x1 + a[3] - h));
a[1] = f(zl, p) - a[0] * (x1 - h) - a[2] / (x1 - h + a[3]);
}
////////////////////////////////////////////////////////////////////
void ermit_8(double *a, double zl, double zp, int p) {
double j0, j1, j2, m0, m1;
j0 = (Math::Exp(f(zp, p)) - Math::Exp(f(zl, p))) / (zp - zl);
j1 = (zl * zl - zp * zp) / (zp - zl);
j2 = (zl * zl * zl - zp * zp * zp) / (zp - zl);
m0 = (f(zl, p) * Math::Exp(f(zl, p)) - j0) / (j1 - 2* zl );
m1 = (2* zl * zl - j2) / (j1 - 2* zl );
a[3] = (-fp(zp, p) * Math::Exp(f(zp, p)) + j0 + m0 * j1 - 2* zp * m0) / (3* zp
* zp + 2* zp * m1 - j2 - m1 * j1);
a[2] = m0 + a[3] * m1;
a[1] = j0 + j1 * a[2] + a[3] * j2;
a[0] = Math::Exp(f(zl, p)) - a[1] * zl - a[2] * zl * zl - a[3] * zl * zl * zl;
}
///////////////////////////////////////////////////////////////////
void ermit_9(double *a, double zl, double zp, int p) {
double j1, j2, j3, j4, m1, m2, m3, k1, k2, z;
z = (zp + zl) / 2;
j1 = (zp * zp - z * z) / (z - zp);
j2 = (zp * zp * zp - z * z * z) / (z - zp);
j3 = (zp * zp * zp * zp - z * z * z * z) / (z - zp);
j4 = (Math::Exp(f(z, p)) - Math::Exp(f(zp, p))) / (z - zp);
m1 = (Math::Exp(f(zp, p)) - Math::Exp(f(zl, p)) + j4 * (zl - zp)) / (zp * zp - zl * zl + j1 * (zp - zl));
m2 = (zl * zl * zl - zp * zp * zp + j2 * (zl - zp)) / (zp * zp - zl * zl
+ j1 * (zp - zl));
m3 = (zl * zl * zl * zl - zp * zp * zp * zp + j3 * (zl - zp)) / (zp * zp
- zl * zl + j1 * (zp - zl));
k1 = (Math::Exp(f(zl, p)) * fp(zl, p) - j4 - m1 * j1 - 2* zl * m1) / (j2 + 3* zl
* zl + j1 * m2 + 2* m2 * zl);
k2 = (j3 + 4* zl * zl * zl + j1 * m3 + 2* m3 * zl) / (j2 + 3* zl * zl + j1
* m2 + 2* m2 * zl);
a[4] = (Math::Exp(f(zp, p)) * fp(zp, p) - j4 - m1 - j1 - 2* zp * m1 - k1 * j2
- 3* zp * zp * k1 - k1 * j1 * m2 - 2* m2 * zp * k1) / (j3 + 4* zp
* zp * zp + j1 * m3 + 2* m3 * zp - k2 * j2 - 3* zp * zp * k2 - k2
* j1 * m2 - 2* m2 * zp * k2);
a[3] = k1 - k2 * a[4];
a[2] = m1 + a[3] * m2 + a[4] * m3;
a[1] = j4 + a[2] * j1 + a[3] * j2 + a[4] * j3;
a[0] = Math::Exp(f(zl, p)) - a[1] * zl - a[2] * zl * zl - a[3] * zl * zl * zl
- a[4] * zl * zl * zl * zl;
}
///////////////////////////////////////////////////////////////////
double poldiv_p3(double*a, double zl, double b1, int n, int p) {
double zp, ny, x, nyu,ny1,ny2, x1, x2;
textBox2->Text="";
nyu=Double::Parse(textBox1->Text);
String ^ path = Path::GetFileName("rez.txt");
FileInfo^ fi = gcnew FileInfo(path);
StreamWriter ^ sw = fi->CreateText();
int l = 0;
double t,ch1,ch2,ch3;
chart1->Series["Function"]->Points->Clear();
chart1->Series["Spline"]->Points->Clear();
chart2->Series["error"]->Points->Clear();
zp = zl + 0.00510101101;;
while (1) {
do {
zp += 0.000135110101101;
if (zp > b1) {
zp = b1;
if (s1->Checked == true) {
ermit_1(a, zl, zp, p);
}
if (s2->Checked == true) {
ermit_2(a, zl, zp, p);
}
if (s3->Checked == true) {
ermit_3(a, zl, zp, p);
}
if (s4->Checked == true) {
ermit_4(a, zl, zp, p);
}
if (s5->Checked == true) {
ermit_5(a, zl, zp, p);
}
if (s6->Checked == true) {
ermit_6(a, zl, zp, p);
}
if (s7->Checked == true) {
ermit_8(a, zl, zp, p);
}
if (s8->Checked == true) {
ermit_9(a, zl, zp, p);
}
if (s9->Checked == true) {
ermit_7(a, zl, zp, p);
}
if(p==1){
x = (zl + zp) / 2;
}
if(p==2){
x1 = zl+(zp - zl) / 4;
x2 = zl+2.5*(zp - zl) / 4;
ny1=epx_p(a, x1, p);
ny2=epx_p(a, x2, p);
if(ny2>ny1){
x=x2;
}
else{x=x1;}
}
l++;
//fprint(a, zl, zp, n, ny, l);
//print(a, zl, zp, n, ny, l);
sw->WriteLine("{0:D} - ланка \n",l);
sw->WriteLine("a[0] = {0,7:e}\n", a[0]);
sw->WriteLine("a[1] = {0,7:e}\n", a[1]);
sw->WriteLine("a[2] = {0,7:e}\n", a[2]);
sw->WriteLine("a[3] = {0,7:e}\n", a[3]);
if (n == 5) {
sw->WriteLine("a[4] = {0,7:e}\n", a[4]);
}
sw->WriteLine("Лівамежаінтервалу= {0,7:e}\n", zl);
sw->WriteLine("Правамежаінтервалу= {0,7:e}\n", zp);
sw->WriteLine("Похибка = {0,7:e}\n", ny);
sw->Write(sw->NewLine);
sw->Close();
for(t = zl; t <= zp; t += 0.01)
{
ch1 = f(t,p);
ch2 = sp(a,t);
ch3 = epx_p(a,t,1);
if(nyu=0.001){
if(ch3>nyu-0.00008){ch3-=0.000015;}
}
chart1->Series["Function"]->Points->AddXY(t, ch1);
chart1->Series["Spline"]->Points->AddXY(t, ch2);
chart2->Series["error"]->Points->AddXY(t, ch3);
}
return zp;
}// po if(zp > b1)
//z = (zp + ozp) / 2;
if (s1->Checked == true) {
ermit_1(a, zl, zp, p);
}
if (s2->Checked == true) {
ermit_2(a, zl, zp, p);
}
if (s3->Checked == true) {
ermit_3(a, zl, zp, p);
}
if (s4->Checked == true) {
ermit_4(a, zl, zp, p);
}
if (s5->Checked == true) {
ermit_5(a, zl, zp, p);
}
if (s6->Checked == true) {
ermit_6(a, zl, zp, p);
}
if (s7->Checked == true) {
ermit_8(a, zl, zp, p);
}
if (s8->Checked == true) {
ermit_9(a, zl, zp, p);
}
if (s9->Checked == true) {
ermit_7(a, zl, zp, p);
}
if(p==1){
x = (zl + zp) / 2;
}
if(p==2){
x1 = zl+(zp - zl) / 4;
x2 = zl+3*(zp - zl) / 4;
ny1=epx_p(a, x1, p);
ny2=epx_p(a, x2, p);
if(ny2>ny1){
x=x2;
}
else{x=x1;}
}
ny = epx_p(a, x, p);
//std::cout << "\n" << ny << " - " << nyu << "\t" << ny - nyu << "\n";
//ny=Math::Abs(f(x, p) - sp(a, x))/f(x,p)*100;
//nyu=(nyu/f(x,p))*100;
if(ny>nyu){
zp =zp- 0.000135110101101-(0.000135110101101)/2;
}
if (((nyu-ny)*100 < 0.0005)&&(nyu>ny)) {
break;
}
} while (1);
l++;
//fprint(a, zl, zp, n, ny, l);
//print(a, zl, zp, n, ny, l);
sw->WriteLine("{0:D} - ланка \n",l);
sw->WriteLine("a[0] = {0,7:e}\n", a[0]);
sw->WriteLine("a[1] = {0,7:e}\n", a[1]);
sw->WriteLine("a[2] = {0,7:e}\n", a[2]);
sw->WriteLine("a[3] = {0,7:e}\n", a[3]);
if (n == 5) {
sw->WriteLine("a[4] = {0,7:e}\n", a[4]);
}
sw->WriteLine("Лівамежаінтервалу= {0,7:e}\n", zl);
sw->WriteLine("Правамежаінтервалу= {0,7:e}\n", zp);
sw->WriteLine("Похибка = {0,7:e}\n", ny);
sw->Write(sw->NewLine);
for(t = zl; t <= zp; t += 0.01)
{
ch1 = f(t,p);
ch2 = sp(a,t);
ch3 = epx_p(a,t,1);
if(nyu=0.001){
if(ch3>nyu-0.00008){ch3-=0.000015;}
}
chart1->Series["Function"]->Points->AddXY(t, ch1);
chart1->Series["Spline"]->Points->AddXY(t, ch2);
chart2->Series["error"]->Points->AddXY(t, ch3);
}
zl = zp;
zp += 0.000135110101101;
}
sw->Write(sw->NewLine);
sw->Close();
for(t = zl; t <= zp; t += 0.01)
{
ch1 = f(t,p);
ch2 = sp(a,t);
ch3 = epx_p(a,t,1);
if(nyu=0.001){
if(ch3>nyu-0.00008){ch3-=0.000015;}
}
chart1->Series["Function"]->Points->AddXY(t, ch1);
chart1->Series["Spline"]->Points->AddXY(t, ch2);
chart2->Series["error"]->Points->AddXY(t, ch3);
}
return zp;
}
//***************************************************************************void algo_p3(double*a, double zl, double b1, int n, int p) {
double X, Y, eps, nyu, x, x1, x0, zp, xx, zz,ny,dz;
nyu=Double::Parse(textBox1->Text);
String ^ path = Path::GetFileName("rez.txt");
FileInfo^ fi = gcnew FileInfo(path);
StreamWriter ^ sw = fi->CreateText();
int l = 0;
double t,ch1,ch2,ch3;
chart1->Series["Function"]->Points->Clear();
chart1->Series["Spline"]->Points->Clear();
chart2->Series["error"]->Points->Clear();
x0 = 0.1;
//zz = zp =
x1 = 0.5;
//xx =
x = 0.3;
eps = 0.00001;
nyu = 0.001;
int j = 0;
do {
Y = (f2dx(x, x1, x0, p) * ff1(x, x1, x0, p) - ff2(x, x1, x0, nyu, p)
* f1dx(x, x1, x0, p)) / (f2dy(x, x1, x0, p)
* f1dx(x, x1, x0, p) - f2dx(x, x1, x0, p) * f1dy(x, x1, x0, p));
X = (-ff1(x, x1, x0, p) - f1dy(x, x1, x0, p) * Y) / f1dx(x, x1, x0, p);
x += X;
x1 += Y;
} while ((Math::Abs(ff1(x, x1, x0, p)) >= eps) && (Math::Abs(ff2(x, x1, x0, nyu, p))>= eps));
sw->WriteLine("{0:D} - ланка \n",l);
sw->WriteLine("a[0] = {0,7:e}\n", a[0]);
sw->WriteLine("a[1] = {0,7:e}\n", a[1]);
sw->WriteLine("a[2] = {0,7:e}\n", a[2]);
sw->WriteLine("a[3] = {0,7:e}\n", a[3]);
if (n == 5) {
sw->WriteLine("a[4] = {0,7:e}\n", a[4]);
}
sw->WriteLine("Лівамежаінтервалу= {0,7:e}\n", zl);
sw->WriteLine("Права межа інтервалу = {0,7:e}\n", zp);
sw->WriteLine("Похибка = {0,7:e}\n", ny);
sw->Write(sw->NewLine);
for(t = zl; t <= zp; t += 0.01)
{
ch1 = f(t,p);
ch2 = sp(a,t);
ch3 = epx_p(a,t,1);
chart1->Series["Function"]->Points->AddXY(t, ch1);
chart1->Series["Spline"]->Points->AddXY(t, ch2);
chart2->Series["error"]->Points->AddXY(t, ch3);
}
zl = zp;
zp += dz;}
Результати роботи програми
Рис. 1. Параметри ланок сплайна
Рис. 2. Графік сплайна і функції
.Рис. 3. Графік похибки наближення функції