add numerical recipes library
This commit is contained in:
23
lib/nr/k_and_r/recipes/tridag.c
Normal file
23
lib/nr/k_and_r/recipes/tridag.c
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
#include "nrutil.h"
|
||||
|
||||
void tridag(a,b,c,r,u,n)
|
||||
float a[],b[],c[],r[],u[];
|
||||
unsigned long n;
|
||||
{
|
||||
unsigned long j;
|
||||
float bet,*gam;
|
||||
|
||||
gam=vector(1,n);
|
||||
if (b[1] == 0.0) nrerror("Error 1 in tridag");
|
||||
u[1]=r[1]/(bet=b[1]);
|
||||
for (j=2;j<=n;j++) {
|
||||
gam[j]=c[j-1]/bet;
|
||||
bet=b[j]-a[j]*gam[j];
|
||||
if (bet == 0.0) nrerror("Error 2 in tridag");
|
||||
u[j]=(r[j]-a[j]*u[j-1])/bet;
|
||||
}
|
||||
for (j=(n-1);j>=1;j--)
|
||||
u[j] -= gam[j+1]*u[j+1];
|
||||
free_vector(gam,1,n);
|
||||
}
|
||||
Reference in New Issue
Block a user