Нужно помочь заполнить форум. Только по теме. Все предложения по его улучшению ко мне в личку
Ребят, помогите
Сообщений 1 страница 2 из 2
Поделиться22008-05-25 17:42:39
#include <stdio.h>
#include <math.h>
#define NRANSI
//#include "nrutil.h"
#include "bibl.h"
#define PI 3.1415926
#define e 0.001
int main(void)
{
int n,ng,i;
double dy,x,y,*xa,*ya,id, *y2,l;
FILE *fp;
fp=fopen("polin21.txt","w");
printf("generation of interpolation tables\n");
printf(" ... 1/(1 + 25*x^2) -1<x<1\n");
// printf(" ... exp(x) 0<x<1 \n");
printf("Globalnay interpolyciy stepeni 20\n");
n=21;
xa=vector(1,n);
ya=vector(1,n);
for (i=1;i<=n;i++)
{
xa[i]=-1.+2.*(i-1.)/(n-1.);
ya[i]=1./(1.+ 25.*xa[i]*xa[i]);
}
printf("\n%9s %16s %13s\n","x","interpolated","error");
for (id=-1;id<=1;id+=e)
{
x=id;
polint(xa,ya,n,x,&y,&dy);
printf("%12.6f %12.6f %4s %11f\n",x,y," ",dy);
fprintf(fp,"%12.6f %12.6f\n",x,y);
}
free_vector(ya,1,n);
free_vector(xa,1,n);
fclose(fp);
fp=fopen("polin5-21.txt","w");
printf("generation of interpolation tables\n");
printf(" ... 1/(1 + 25*x^2) -1<x<1\n");
// printf(" ... exp(x) 0<x<1 \n");
printf("Globalnay interpolyciy stepeni 5 po 21 tocke \n");
n=6;
ng=20;
l=-1;
xa=vector(1,n);
ya=vector(1,n);
printf("\n%9s %16s %13s\n","x","interpolated","error");
for(l=-1;l<=1-2.*(n-1.)/(ng);l+=2./ng)
{
for (i=1;i<=n;i++)
{
xa[i]=l+2.*(i-1.)/(ng);
ya[i]=1./(1.+ 25.*xa[i]*xa[i]);
}
for (id=l+2*(n/2.-1)/ng;id<l+2*(n/2.)/ng ;id+=e)
{
x=id;
polint(xa,ya,n,x,&y,&dy);
printf("%12.6f %12.6f %4s %11f\n",x,y," ",dy);
fprintf(fp,"%12.6f %12.6f\n",x,y);
}
}
free_vector(ya,1,n);
free_vector(xa,1,n);
fclose(fp);
fp=fopen("polin6.txt","w");
printf("generation of interpolation tables\n");
printf(" ... 1/(1 + 25*x^2) -1<x<1\n");
// printf(" ... exp(x) 0<x<1 \n");
printf("Globalnay interpolyciy stepeni 5\n");
n=6;
xa=vector(1,n);
ya=vector(1,n);
for (i=1;i<=n;i++)
{
xa[i]=-1.+2.*(i-1.)/(n-1.);
ya[i]=1./(1.+ 25.*xa[i]*xa[i]);
}
printf("\n%9s %16s %13s\n","x","interpolated","error");
for (id=-1;id<=1;id+=e)
{
x=id;
polint(xa,ya,n,x,&y,&dy);
printf("%12.6f %12.6f %4s %11f\n",x,y," ",dy);
fprintf(fp,"%12.6f %12.6f\n",x,y);
}
free_vector(ya,1,n);
free_vector(xa,1,n);
fclose(fp);
fp=fopen("spline21.txt","w");
printf("generation of interpolation tables\n");
printf(" ... 1/(1 + 25*x^2) -1<x<1\n");
// printf(" ... exp(x) 0<x<1 \n");
printf("Sline interpolyciy v 21 tocke\n");
n=21;
xa=vector(1,n);
ya=vector(1,n);
y2=vector(1,n);
for (i=1;i<=n;i++)
{
xa[i]=-1.+2.*(i-1.)/(n-1.);
ya[i]=1./(1.+ 25.*xa[i]*xa[i]);
}
spline(xa,ya,n,0,0,y2);
printf("\n%9s %17s\n","x","interpolation");
for (id=-1;id<=1;id+=e)
{
x=id;
splint(xa,ya,y2,n,x,&y);
printf("%12.6f %12.6f\n",x,y);
fprintf(fp,"%12.6f %12.6f\n",x,y);
}
free_vector(y2,1,n);
free_vector(ya,1,n);
free_vector(xa,1,n);
fclose(fp);
return 0;
}
#undef NRANSI
Интерполяция от меня!
Бугога **Это по теме?**