예제 #1
0
void NR::voltra(const DP t0, const DP h, Vec_O_DP &t, Mat_O_DP &f,
	DP g(const int, const DP),
	DP ak(const int, const int, const DP, const DP))
{
	int i,j,k,l;
	DP d,sum;

	int m=f.nrows();
	int n=f.ncols();
	Vec_INT indx(m);
	Vec_DP b(m);
	Mat_DP a(m,m);
	t[0]=t0;
	for (k=0;k<m;k++) f[k][0]=g(k,t[0]);
	for (i=1;i<n;i++) {
		t[i]=t[i-1]+h;
		for (k=0;k<m;k++) {
			sum=g(k,t[i]);
			for (l=0;l<m;l++) {
				sum += 0.5*h*ak(k,l,t[i],t[0])*f[l][0];
				for (j=1;j<i;j++)
					sum += h*ak(k,l,t[i],t[j])*f[l][j];
				if (k == l)
					a[k][l]=1.0-0.5*h*ak(k,l,t[i],t[i]);
				else
					a[k][l] = -0.5*h*ak(k,l,t[i],t[i]);
			}
			b[k]=sum;
		}
		ludcmp(a,indx,d);
		lubksb(a,indx,b);
		for (k=0;k<m;k++) f[k][i]=b[k];
	}
}
예제 #2
0
파일: interp.cpp 프로젝트: HunterAllman/kod
void NR::interp(Mat_O_DP &uf, Mat_I_DP &uc)
{
	int ic,iif,jc,jf,nc;

	int nf=uf.nrows();
	nc=nf/2+1;
	for (jc=0;jc<nc;jc++)
		for (ic=0;ic<nc;ic++) uf[2*ic][2*jc]=uc[ic][jc];
	for (jf=0;jf<nf;jf+=2)
		for (iif=1;iif<nf-1;iif+=2)
			uf[iif][jf]=0.5*(uf[iif+1][jf]+uf[iif-1][jf]);
	for (jf=1;jf<nf-1;jf+=2)
		for (iif=0;iif<nf;iif++)
			uf[iif][jf]=0.5*(uf[iif][jf+1]+uf[iif][jf-1]);
}
예제 #3
0
파일: rstrct.cpp 프로젝트: HunterAllman/kod
void NR::rstrct(Mat_O_DP &uc, Mat_I_DP &uf)
{
	int ic,iif,jc,jf,ncc;

	int nc=uc.nrows();
	ncc=2*nc-2;
	for (jf=2,jc=1;jc<nc-1;jc++,jf+=2) {
		for (iif=2,ic=1;ic<nc-1;ic++,iif+=2) {
			uc[ic][jc]=0.5*uf[iif][jf]+0.125*(uf[iif+1][jf]+uf[iif-1][jf]
				+uf[iif][jf+1]+uf[iif][jf-1]);
		}
	}
	for (jc=0,ic=0;ic<nc;ic++,jc+=2) {
		uc[ic][0]=uf[jc][0];
		uc[ic][nc-1]=uf[jc][ncc];
	}
	for (jc=0,ic=0;ic<nc;ic++,jc+=2) {
		uc[0][ic]=uf[0][jc];
		uc[nc-1][ic]=uf[ncc][jc];
	}
}