问题描述
我正在寻找一种量化由矩阵元素的数值误差引起的矩阵向量相乘误差的方法。在我最近的项目中,我实现了一个生成翻译矩阵的例程。
// p decides the size of the truncated matrix (truncation number)
void genHorizCoaxMat(const double wavNum,const double t,const double* a_coeffs,const double* b_coeffs,const int p,cuDoubleComplex* mat)
我使用以下例程测试矩阵生成的稳定性:
void testGenCoaxStability()
{
double t = 0.02;
double delta_t = 1.0e-16; // fluctuation
int p = 10; // truncation number
double freq = 5000,wavNum = 2*PI*freq/SOUND_SPEED; // frequency and wavenumber
double *a_coeffs = (double*)malloc(TRANsveCSZ(ENLP(p))*sizeof(double)); // auxiliary numbers
double *b_coeffs = (double*)malloc(TRANsveCSZ(ENLP(p))*sizeof(double)); // auxiliary numbers
// generate auxiliary coefficients
for(int n = 0; n < ENLP(p); n++)
{
for(int m = -n; m <= n; m++)
{
a_coeffs[NM2IDX0(n,m)] = aCoeff(n,m);
b_coeffs[NM2IDX0(n,m)] = bCoeff(n,m);
}
}
cuDoubleComplex *mat1 = (cuDoubleComplex*)malloc(COAXMATSZ(p)*sizeof(cuDoubleComplex));
cuDoubleComplex *mat2 = (cuDoubleComplex*)malloc(COAXMATSZ(p)*sizeof(cuDoubleComplex));
genHorizCoaxMat(wavNum,t,a_coeffs,b_coeffs,p,mat1); // generate matrix with no fluctuation
genHorizCoaxMat(wavNum,t+delta_t,mat2); // with fluctuation
free(a_coeffs);
free(b_coeffs);
subArr(mat1,mat2,COAXMATSZ(p)); // subtract two arrays for comparison
printf("Numerical error induced by a fluctuation on t:\n");
for(int i = 0; i < COAXMATSZ(p); i++)
{
printf("(%lf,%lf) ",cuCreal(mat1[i]),cuCimag(mat1[i]));
}
printf("\n");
free(mat1);
free(mat2);
}
正如我从其印刷物中发现的那样,当't'小而'p'大时,参数't'的微小波动会导致某些元素的不可忽略的误差:
Numerical error induced by a fluctuation on t:
(0.000000,-0.000000) (0.000000,0.000000) (-0.000000,-0.000000) (-0.000000,0.000000) (0.000000,0.000002) (-0.000000,-0.000002) (-0.000000,0.000035) (-0.000000,-0.000035) (0.000000,0.000525) (-0.000000,0.000035) (0.000000,-0.000523) (-0.000000,0.008514) (0.000000,0.000002) (0.000000,0.000522) (-0.000000,-0.008499) (0.000000,0.147949) (0.000000,0.000034) (-0.000000,-0.000522) (0.000000,0.008499) (0.000000,-0.147705) (-0.000000,2.710938) (0.000000,-0.000035) (-0.000000,0.000523) (-0.000000,-0.008499) (-0.000000,0.147705) (0.000000,-2.707031) (0.000000,53.250000) (-0.000000,-0.000525) (-0.000000,0.008514) (-0.000000,-0.147949) (-0.000000,2.707031) (-0.000000,-53.250000) (0.000000,1104.000000) (0.000000,-0.000029) (-0.000000,0.000029) (0.000000,-0.000444) (-0.000000,-0.000030) (0.000000,0.000449) (-0.000000,-0.007401) (-0.000000,-0.000002) (0.000000,0.000030) (0.000000,-0.000451) (-0.000000,0.007446) (0.000000,-0.129639) (0.000000,-0.000030) (-0.000000,0.000451) (0.000000,-0.007462) (0.000000,0.130127) (-0.000000,-2.414062) (0.000000,0.000029) (-0.000000,-0.000449) (-0.000000,-0.130127) (0.000000,2.417969) (0.000000,-47.875000) (-0.000000,0.000444) (-0.000000,-0.007416) (-0.000000,0.129883) (-0.000000,-2.414062) (-0.000000,47.875000) (0.000000,-1000.000000) (0.000000,0.000001) (-0.000000,-0.000001) (-0.000000,0.000016) (-0.000000,-0.000017) (0.000000,0.000270) (-0.000000,0.000018) (0.000000,-0.000286) (-0.000000,0.004791) (-0.000000,0.000001) (0.000000,-0.000019) (0.000000,0.000293) (-0.000000,-0.004936) (0.000000,0.088135) (0.000000,0.000018) (-0.000000,-0.000293) (0.000000,0.004982) (0.000000,-0.089600) (-0.000000,1.683594) (-0.000000,-0.000017) (-0.000000,0.000286) (-0.000000,-0.004936) (-0.000000,0.089600) (0.000000,-1.691406) (0.000000,34.187500) (0.000000,-0.000270) (-0.000000,0.004776) (-0.000000,-0.088135) (-0.000000,-34.187500) (0.000000,725.000000) (0.000000,-0.000005) (-0.000000,0.000007) (0.000000,-0.000111) (-0.000000,-0.000008) (0.000000,0.000130) (-0.000000,-0.002247) (-0.000000,-0.000001) (0.000000,0.000008) (0.000000,-0.000139) (-0.000000,0.002441) (0.000000,-0.045044) (-0.000000,-0.000008) (-0.000000,0.000139) (0.000000,-0.002502) (0.000000,0.046875) (-0.000000,-0.916016) (-0.000000,0.000007) (-0.000000,-0.000130) (-0.000000,0.002441) (-0.000000,-0.046875) (0.000000,0.931641) (0.000000,-19.343750) (0.000000,-0.000005) (0.000000,0.000111) (-0.000000,-0.002251) (-0.000000,0.044922) (-0.000000,19.343750) (0.000000,-426.000000) (0.000000,0.000027) (-0.000000,-0.000040) (-0.000000,0.000729) (-0.000000,-0.000003) (0.000000,0.000046) (-0.000000,-0.000872) (0.000000,0.016876) (-0.000000,-0.000046) (0.000000,0.000919) (0.000000,-0.018402) (-0.000000,0.376953) (-0.000000,0.000040) (-0.000000,-0.000872) (-0.000000,0.018402) (0.000000,-0.390625) (0.000000,8.531250) (0.000000,-0.000027) (-0.000000,0.000727) (-0.000000,-0.016876) (-0.000000,0.378906) (-0.000000,-8.531250) (0.000000,196.250000) (0.000000,-0.000010) (-0.000000,0.000208) (0.000000,-0.004333) (-0.000000,0.000010) (0.000000,-0.000232) (0.000000,0.005135) (-0.000000,-0.112793) (-0.000000,-0.000007) (-0.000000,0.000208) (-0.000000,-0.005135) (0.000000,0.120117) (0.000000,-2.843750) (-0.000000,0.004326) (-0.000000,-0.113037) (-0.000000,2.843750) (0.000000,-70.375000) (0.000000,-0.000028) (0.000000,0.000655) (-0.000000,0.000036) (0.000000,-0.000946) (-0.000000,0.023071) (-0.000000,-0.000028) (-0.000000,0.000946) (0.000000,-0.026001) (0.000000,0.686523) (-0.000000,-0.000655) (-0.000000,-0.686523) (0.000000,18.937500) (0.000000,0.000093) (-0.000000,-0.002705) (-0.000000,-0.000093) (0.000000,0.003510) (0.000000,-0.109375) (-0.000000,-0.002708) (-0.000000,0.109375) (0.000000,-3.578125) (0.000000,-0.000222) (0.000000,0.009476) (-0.000000,-0.009476) (0.000000,0.424805) (0.000000,-0.023834)
正如我分析的那样,当n >> x时,不稳定性来自第二种类型的球贝塞尔函数y_n(x)。由于生成此矩阵的目的是进行矩阵向量乘法,因此我想从理论上分析这些数字误差是否导致乘积中的大误差。我的问题应该形式化为:对于给定的向量x,定义一个函数f(T)= Tx,其中T是一个矩阵,如何描述波动Delta_T对函数f的影响?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)