File: fbase.c

package info (click to toggle)
fitsh 0.9.2-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 2,768 kB
  • ctags: 4,050
  • sloc: ansic: 53,352; makefile: 1,120; sh: 25
file content (65 lines) | stat: -rw-r--r-- 1,480 bytes parent folder | download | duplicates (2)
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
/*****************************************************************************/
/* fbase.c								     */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* (c) 2008; Pal, A.							     */
/*****************************************************************************/

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>

#include "math/spline/spline.h"

#include "fbase.h"

/*****************************************************************************/

int fbase_spline(double **fbase,int order,int n)
{
 double	*y1,*y2,x;
 int	i,o;

 y1=(double *)malloc(sizeof(double)*(order+1));
 y2=(double *)malloc(sizeof(double)*(order+1));

 for ( o=0 ; o<=order ; o++ )
  {	for ( i=0 ; i<=order ; i++ )
	 {	y1[i]=(i==o?1.0:0.0);	}
	natspline_coeff(y1,order+1,y2);
	for ( i=0 ; i<n ; i++ )
	 {	x=(double)order*(0.5+(double)i)/(double)n;
		fbase[o][i]=natspline_inter(y1,y2,order+1,x);
	 }
  }

 free(y2);
 free(y1);
 
 return(0);
}

int fbase_polynomial(double **fbase,int order,int n)
{
 int	i,o;
 double	x,p0,p1,p2;

 for ( i=0 ; i<n ; i++ )
  {	x=2.0*((0.5+(double)i)/(double)n)-1.0;
	p0=1.0;
	p1=x;
	for ( o=0 ;  o<=order ; o++ )
	 {	fbase[o][i]=p0;
		p2=((double)(2*o+3)*x*p1-(double)(o+1)*p0)/(double)(o+2);
		p0=p1;
		p1=p2;
	 }
  }

 return(0);
}

/*****************************************************************************/