stoep.c

来自「该程序是用vc开发的对动态数组进行管理的DLL」· C语言 代码 · 共 155 行

C
155
字号
/* Copyright (c) Colorado School of Mines, 2003.*//* All rights reserved.                       *//*********************** self documentation **********************//*****************************************************************************STOEP - Functions to solve a symmetric Toeplitz linear system of equations	 Rf=g for fstoepd		solve a symmetric Toeplitz system - doublesstoepf		solve a symmetric Toeplitz system - floats******************************************************************************Function Prototypes:void stoepd (int n, double r[], double g[], double f[], double a[]);void stoepf (int n, float r[], float g[], float f[], float a[]);******************************************************************************Input:n		dimension of systemr		array[n] of top row of Toeplitz matrixg		array[n] of right-hand-side column vectorOutput:f		array[n] of solution (left-hand-side) column vectora		array[n] of solution to Ra=v (Claerbout, FGDP, p. 57)******************************************************************************Notes:These routines do NOT solve the case when the main diagonal is zero, itjust silently returns.The left column of the Toeplitz matrix is assumed to be equal to the toprow (as specified in r); i.e., the Toeplitz matrix is assumed symmetric.******************************************************************************Author:  Dave Hale, Colorado School of Mines, 06/02/89*****************************************************************************//**************** end self doc ********************************/#include "cwp.h"void stoepd (int n, double r[], double g[], double f[], double a[])/*****************************************************************************Solve a symmetric Toeplitz linear system of equations Rf=g for f(double version)******************************************************************************Input:n		dimension of systemr		array[n] of top row of Toeplitz matrixg		array[n] of right-hand-side column vectorOutput:f		array[n] of solution (left-hand-side) column vectora		array[n] of solution to Ra=v (Claerbout, FGDP, p. 57)******************************************************************************Notes:This routine does NOT solve the case when the main diagonal is zero, itjust silently returns.The left column of the Toeplitz matrix is assumed to be equal to the toprow (as specified in r); i.e., the Toeplitz matrix is assumed symmetric.******************************************************************************Author:  Dave Hale, Colorado School of Mines, 06/02/89*****************************************************************************/{	int i,j;	double v,e,c,w,bot;	if (r[0] == 0.0) return;	a[0] = 1.0;	v = r[0];	f[0] = g[0]/r[0];	for (j=1; j<n; j++) {				/* solve Ra=v as in Claerbout, FGDP, p. 57 */		a[j] = 0.0;		f[j] = 0.0;		for (i=0,e=0.0; i<j; i++)			e += a[i]*r[j-i];		c = e/v;		v -= c*e;		for (i=0; i<=j/2; i++) {			bot = a[j-i]-c*a[i];			a[i] -= c*a[j-i];			a[j-i] = bot;		}		/* use a and v above to get f[i], i = 0,1,2,...,j */		for (i=0,w=0.0; i<j; i++)			w += f[i]*r[j-i];		c = (w-g[j])/v;		for (i=0; i<=j; i++)			f[i] -= c*a[j-i];	}}void stoepf (int n, float r[], float g[], float f[], float a[])/*****************************************************************************Solve a symmetric Toeplitz linear system of equations Rf=g for f(float version) ******************************************************************************Input:n		dimension of systemr		array[n] of top row of Toeplitz matrixg		array[n] of right-hand-side column vectorOutput:f		array[n] of solution (left-hand-side) column vectora		array[n] of solution to Ra=v (Claerbout, FGDP, p. 57)******************************************************************************Notes:This routine does NOT solve the case when the main diagonal is zero, itjust silently returns.The left column of the Toeplitz matrix is assumed to be equal to the toprow (as specified in r); i.e., the Toeplitz matrix is assumed symmetric.******************************************************************************Author:  Dave Hale, Colorado School of Mines, 06/02/89*****************************************************************************/{	int i,j;	float v,e,c,w,bot;	if (r[0] == 0.0) return;	a[0] = 1.0;	v = r[0];	f[0] = g[0]/r[0];	for (j=1; j<n; j++) {				/* solve Ra=v as in Claerbout, FGDP, p. 57 */		a[j] = 0.0;		f[j] = 0.0;		for (i=0,e=0.0; i<j; i++)			e += a[i]*r[j-i];		c = e/v;		v -= c*e;		for (i=0; i<=j/2; i++) {			bot = a[j-i]-c*a[i];			a[i] -= c*a[j-i];			a[j-i] = bot;		}		/* use a and v above to get f[i], i = 0,1,2,...,j */		for (i=0,w=0.0; i<j; i++)			w += f[i]*r[j-i];		c = (w-g[j])/v;		for (i=0; i<=j; i++)			f[i] -= c*a[j-i];	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?