#include <stdio.h>
#include <conio.h>
#include <math.h>
#include "Marq.h"
#include "nrutil.h"
Go to the source code of this file.
|
void | polint (float xa[], float ya[], int n, float x, float *y, float *dy) |
|
void | ratint (float xa[], float ya[], int n, float x, float *y, float *dy) |
|
void | spline (float x[], float y[], int n, float yp1, float ypn, float y2[]) |
|
void | splint (float xa[], float ya[], float y2a[], int n, float x, float *y) |
|
int | testpolintfull (void) |
|
int | testpolintlambda (void) |
|
int | testpolintshort (void) |
|
int | testsplint (void) |
|
int | testsplintrc (void) |
|
§ FREERETURN
§ PI
§ TINY
§ polint()
void polint |
( |
float |
xa[], |
|
|
float |
ya[], |
|
|
int |
n, |
|
|
float |
x, |
|
|
float * |
y, |
|
|
float * |
dy |
|
) |
| |
§ ratint()
void ratint |
( |
float |
xa[], |
|
|
float |
ya[], |
|
|
int |
n, |
|
|
float |
x, |
|
|
float * |
y, |
|
|
float * |
dy |
|
) |
| |
§ spline()
void spline |
( |
float |
x[], |
|
|
float |
y[], |
|
|
int |
n, |
|
|
float |
yp1, |
|
|
float |
ypn, |
|
|
float |
y2[] |
|
) |
| |
Definition at line 138 of file Interpolation.c.
References free_vector(), p, and vector().
Referenced by testsplint(), and testsplintrc().
141 float p,qn,sig,un,*u;
148 u[1]=(3.0/(x[2]-x[1]))*((y[2]-y[1])/(x[2]-x[1])-yp1);
153 sig=(x[i]-x[i-1])/(x[i+1]-x[i-1]);
156 u[i]=(y[i+1]-y[i])/(x[i+1]-x[i]) - (y[i]-y[i-1])/(x[i]-x[i-1]);
157 u[i]=(6.0*u[i]/(x[i+1]-x[i-1])-sig*u[i-1])/
p;
164 un=(3.0/(x[n]-x[n-1]))*(ypn-(y[n]-y[n-1])/(x[n]-x[n-1]));
166 y2[n]=(un-qn*u[n-1])/(qn*y2[n-1]+1.0);
168 y2[k]=y2[k]*y2[k+1]+u[k];
§ splint()
void splint |
( |
float |
xa[], |
|
|
float |
ya[], |
|
|
float |
y2a[], |
|
|
int |
n, |
|
|
float |
x, |
|
|
float * |
y |
|
) |
| |
§ testpolintfull()
int testpolintfull |
( |
void |
| ) |
|
Definition at line 308 of file Interpolation.c.
References free_vector(), PI, polint(), and vector().
312 float dy,f,x,y,*xa,*ya;
314 printf(
"generation of interpolation tables\n");
315 printf(
" ... sin(x) 0<x<PI\n");
316 printf(
" ... exp(x) 0<x<1 \n");
317 printf(
"how many entries go in these tables?\n");
318 if (scanf(
"%d",&n) == EOF)
return 1;
321 for (nfunc=1;nfunc<=2;nfunc++)
325 printf(
"\nsine function from 0 to PI\n");
336 printf(
"\nexponential function from 0 to 1\n");
348 printf(
"\n%9s %13s %16s %13s\n",
"x",
"f(x)",
"interpolated",
"error");
363 printf(
"%12.6f %12.6f %12.6f %4s %11f\n", x,f,y,
" ",dy);
366 printf(
"\n***********************************\n");
367 printf(
"press RETURN\n");
void polint(float xa[], float ya[], int n, float x, float *y, float *dy)
§ testpolintlambda()
int testpolintlambda |
( |
void |
| ) |
|
Definition at line 379 of file Interpolation.c.
References dvector(), nrerror(), and polint().
382 int i,n, l = 1, linit;
390 if((nf = fopen(
"In.dat",
"r")) == NULL)
394 fscanf(nf,
"%f%f", &xa[l], &ya[l]);
395 printf(
"%d %12.6f %12.6f \n", l, xa[l],ya[l]);
402 nf = fopen(
"Is.dat",
"w");
406 polint(&xa[i], &ya[i],2,(
float) i+linit,&y,&dy);
407 printf(
"\n%d %12.6f %12.6f ", i, xa[i],ya[i]);
408 printf(
"\n%d %d %12.6f %12.6f", i, i+linit,y,dy);
409 printf(
"\n**************");
411 fprintf(nf,
"%12.6lf %12.6lf %d %12.6lf \n",xa[i],ya[i], i+linit, y);
void polint(float xa[], float ya[], int n, float x, float *y, float *dy)
§ testpolintshort()
int testpolintshort |
( |
void |
| ) |
|
Definition at line 214 of file Interpolation.c.
References free_vector(), PI, polint(), and vector().
218 float dy,f,x,y,*xa,*ya;
220 printf(
"generation of interpolation tables\n");
221 printf(
" ... sin(x) 0<x<PI\n");
222 printf(
" ... exp(x) 0<x<1 \n");
223 printf(
"how many entries go in these tables?\n");
224 if (scanf(
"%d",&n) == EOF)
return 1;
226 for (nfunc=1;nfunc<=2;nfunc++)
234 printf(
"\nsine function from 0 to PI\n");
240 printf(
"%12.6f %12.6f \n", xa[i],ya[i]);
247 printf(
"\nexponential function from 0 to 1\n");
253 printf(
"%12.6f %12.6f \n", xa[i],ya[i]);
263 printf(
"\n%9s %13s %16s %13s\n",
"x",
"f(x)",
"interpolated",
"error");
288 polint(&xa[n/2],&ya[n/2],5,x,&y,&dy);
289 printf(
"%12.6f %12.6f %12.6f %4s %11f\n", x,f,y,
" ",dy);
295 printf(
"\n***********************************\n");
296 printf(
"press RETURN\n");
void polint(float xa[], float ya[], int n, float x, float *y, float *dy)
§ testsplint()
Definition at line 419 of file Interpolation.c.
References free_vector(), PI, spline(), splint(), and vector().
423 float f,x,y,yp1,ypn,*xa,*ya,*y2;
425 printf(
"generation of interpolation tables\n");
426 printf(
" ... sin(x) 0<x<PI\n");
427 printf(
" ... exp(x) 0<x<1 \n");
428 printf(
"how many entries go in these tables?\n");
429 if (scanf(
"%d",&n) == EOF)
return 1;
433 for (nfunc=1;nfunc<=2;nfunc++)
437 printf(
"\nsine function from 0 to PI\n");
449 printf(
"\nexponential function from 0 to 1\n");
464 spline(xa,ya,n,yp1,ypn,y2);
466 printf(
"\n%9s %13s %16s %13s\n",
"x",
"f(x)",
"interpolated",
"error");
481 printf(
"%12.6f %12.6f %12.6f \n", x,f,y);
484 printf(
"\n***********************************\n");
485 printf(
"press RETURN\n");
void splint(float xa[], float ya[], float y2a[], int n, float x, float *y)
void spline(float x[], float y[], int n, float yp1, float ypn, float y2[])
§ testsplintrc()
int testsplintrc |
( |
void |
| ) |
|
Definition at line 497 of file Interpolation.c.
References free_vector(), nrerror(), spline(), splint(), and vector().
500 int i,n,nfunc, linit, l = 1;
506 if((nf = fopen(
"In.dat",
"r")) == NULL)
510 fscanf(nf,
"%lf%lf", &a, &b);
521 if((nf = fopen(
"In.dat",
"r")) == NULL)
527 fscanf(nf,
"%f%f", &xa[i], &ya[i]);
528 printf(
"%d %12.6f %12.6f \n", i, xa[i],ya[i]);
531 printf(
"**********************************************\n");
555 spline(xa,ya,l,yp1,ypn,y2);
558 nf = fopen(
"Is.dat",
"w");
563 splint(&xa[i], &ya[i],&y2[i],3,(
float) i+linit,&y);
566 printf(
"\n%d %12.6f %12.6f %d %d %12.6f ", i, xa[i],ya[i],i, i+linit,y);
570 fprintf(nf,
"%12.6lf %12.6lf %d %12.6lf \n",xa[i],ya[i], i+linit, y);
void splint(float xa[], float ya[], float y2a[], int n, float x, float *y)
void spline(float x[], float y[], int n, float yp1, float ypn, float y2[])