Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/164.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何分析矩阵元素波动引起的矩阵向量积数值误差_C++_Matrix_Numerical Analysis - Fatal编程技术网

C++ 如何分析矩阵元素波动引起的矩阵向量积数值误差

C++ 如何分析矩阵元素波动引起的矩阵向量积数值误差,c++,matrix,numerical-analysis,C++,Matrix,Numerical Analysis,我正在寻找一种方法来量化由矩阵元素的数值误差引起的矩阵向量乘法误差。在我最近的项目中,我实现了一个生成翻译矩阵的例程 // 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, cuDoub

我正在寻找一种方法来量化由矩阵元素的数值误差引起的矩阵向量乘法误差。在我最近的项目中,我实现了一个生成翻译矩阵的例程

// 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,a_coeffs,b_coeffs,p,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);
}

正如我所分析的,当n>>x时,不稳定性来自第二类y_n(x)的球形贝塞尔函数。由于生成此矩阵的目的是进行矩阵向量乘法,我想从理论上分析这些数值误差是否会导致乘积中的较大误差。我的问题应该被形式化为,对于给定的向量x,定义一个函数f(T)=Tx,其中T是一个矩阵,如何描述波动Delta_T对函数f的影响?

这个矩阵的作用是什么?为了跟进Evg,如果矩阵的条件数很高,你可能会有很大的错误。如果条件数较低,则不会出现较大的错误@Evg@TohpiMou起初我认为条件数是为Ax=b在b上的稳定性定义的。然后我意识到,x上f(x)=Ax的条件数与b上的Ax=b的条件数相同。然而,我的问题是研究A上f(A)=Ax的稳定性,因为A是波动的来源。似乎是另一个问题。该矩阵的作用是什么?为了跟进Evg,如果矩阵的条件数较高,则可能会有较大的错误。如果条件数较低,则不会出现较大的错误@Evg@TohpiMou起初我认为条件数是为Ax=b在b上的稳定性定义的。然后我意识到,x上f(x)=Ax的条件数与b上的Ax=b的条件数相同。然而,我的问题是研究A上f(A)=Ax的稳定性,因为A是波动的来源。这似乎是另一个问题。
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.000000) (0.000000,0.000000) (-0.000000,-0.000000) (0.000000,0.000000) (-0.000000,-0.000000) (0.000000,0.000000) (-0.000000,-0.000000) (0.000000,0.000000) (-0.000000,-0.000000) (-0.000000,0.000000) (0.000000,-0.000000) (-0.000000,0.000000) (0.000000,-0.000000) (-0.000000,0.000000) (0.000000,-0.000000) (-0.000000,0.000000) (-0.000000,-0.000000) (0.000000,0.000000) (0.000000,-0.000000) (0.000000,0.000000) (-0.000000,-0.000000) (0.000000,0.000000) (-0.000000,-0.000000) (0.000000,0.000000) (-0.000000,-0.000000) (0.000000,0.000002) (-0.000000,-0.000000) (-0.000000,0.000000) (-0.000000,-0.000000) (0.000000,0.000000) (0.000000,-0.000000) (-0.000000,0.000000) (0.000000,-0.000000) (-0.000000,0.000000) (0.000000,-0.000002) (-0.000000,0.000035) (-0.000000,-0.000000) (-0.000000,0.000000) (-0.000000,-0.000000) (-0.000000,0.000000) (0.000000,-0.000000) (0.000000,0.000000) (-0.000000,-0.000000) (0.000000,0.000002) (-0.000000,-0.000035) (0.000000,0.000525) (-0.000000,-0.000000) (-0.000000,0.000000) (-0.000000,-0.000000) (-0.000000,0.000000) (-0.000000,-0.000000) (0.000000,0.000000) (0.000000,-0.000002) (-0.000000,0.000035) (0.000000,-0.000523) (-0.000000,0.008514) (0.000000,-0.000000) (-0.000000,0.000000) (-0.000000,-0.000000) (-0.000000,0.000000) (-0.000000,-0.000000) (-0.000000,0.000002) (0.000000,-0.000035) (0.000000,0.000522) (-0.000000,-0.008499) (0.000000,0.147949) (0.000000,-0.000000) (0.000000,0.000000) (-0.000000,-0.000000) (-0.000000,0.000000) (-0.000000,-0.000002) (-0.000000,0.000034) (-0.000000,-0.000522) (0.000000,0.008499) (0.000000,-0.147705) (-0.000000,2.710938) (0.000000,-0.000000) (0.000000,0.000000) (-0.000000,-0.000000) (-0.000000,0.000002) (-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.000000) (0.000000,0.000000) (0.000000,-0.000002) (-0.000000,0.000035) (-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.000000) (0.000000,0.000000) (-0.000000,-0.000000) (0.000000,0.000000) (-0.000000,-0.000000) (0.000000,0.000000) (-0.000000,-0.000000) (0.000000,0.000000) (-0.000000,-0.000000) (-0.000000,-0.000000) (0.000000,0.000000) (0.000000,-0.000000) (-0.000000,0.000000) (0.000000,-0.000000) (-0.000000,0.000000) (0.000000,-0.000000) (-0.000000,0.000000) (0.000000,-0.000002) (-0.000000,-0.000000) (-0.000000,0.000000) (0.000000,-0.000000) (0.000000,0.000000) (-0.000000,-0.000000) (0.000000,0.000000) (-0.000000,-0.000000) (0.000000,0.000002) (-0.000000,-0.000029) (-0.000000,-0.000000) (-0.000000,0.000000) (-0.000000,-0.000000) (0.000000,0.000000) (0.000000,-0.000000) (-0.000000,0.000000) (0.000000,-0.000002) (-0.000000,0.000029) (0.000000,-0.000444) (-0.000000,-0.000000) (-0.000000,0.000000) (-0.000000,-0.000000) (-0.000000,0.000000) (0.000000,-0.000000) (0.000000,0.000002) (-0.000000,-0.000030) (0.000000,0.000449) (-0.000000,-0.007401) (-0.000000,-0.000000) (-0.000000,0.000000) (-0.000000,-0.000000) (-0.000000,0.000000) (-0.000000,-0.000002) (0.000000,0.000030) (0.000000,-0.000451) (-0.000000,0.007446) (0.000000,-0.129639) (0.000000,-0.000000) (-0.000000,0.000000) (-0.000000,-0.000000) (-0.000000,0.000002) (-0.000000,-0.000030) (-0.000000,0.000451) (0.000000,-0.007462) (0.000000,0.130127) (-0.000000,-2.414062) (0.000000,-0.000000) (0.000000,0.000000) (-0.000000,-0.000002) (-0.000000,0.000029) (-0.000000,-0.000449) (-0.000000,0.007446) (0.000000,-0.130127) (0.000000,2.417969) (0.000000,-47.875000) (-0.000000,-0.000000) (-0.000000,0.000002) (-0.000000,-0.000029) (-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.000000) (0.000000,0.000000) (-0.000000,-0.000000) (0.000000,0.000000) (-0.000000,-0.000000) (0.000000,0.000000) (-0.000000,-0.000000) (0.000000,0.000001) (-0.000000,-0.000000) (0.000000,0.000000) (0.000000,-0.000000) (-0.000000,0.000000) (0.000000,-0.000000) (-0.000000,0.000000) (0.000000,-0.000001) (-0.000000,0.000016) (-0.000000,-0.000000) (-0.000000,0.000000) (0.000000,-0.000000) (0.000000,0.000000) (-0.000000,-0.000000) (0.000000,0.000001) (-0.000000,-0.000017) (0.000000,0.000270) (-0.000000,-0.000000) (-0.000000,0.000000) (-0.000000,-0.000000) (0.000000,0.000000) (0.000000,-0.000001) (-0.000000,0.000018) (0.000000,-0.000286) (-0.000000,0.004791) (-0.000000,-0.000000) (-0.000000,0.000000) (-0.000000,-0.000000) (-0.000000,0.000001) (0.000000,-0.000019) (0.000000,0.000293) (-0.000000,-0.004936) (0.000000,0.088135) (0.000000,-0.000000) (-0.000000,0.000000) (-0.000000,-0.000001) (-0.000000,0.000018) (-0.000000,-0.000293) (0.000000,0.004982) (0.000000,-0.089600) (-0.000000,1.683594) (-0.000000,-0.000000) (0.000000,0.000001) (-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.000001) (-0.000000,0.000016) (-0.000000,-0.000270) (-0.000000,0.004776) (-0.000000,-0.088135) (-0.000000,1.683594) (-0.000000,-34.187500) (0.000000,725.000000) (0.000000,-0.000000) (0.000000,0.000000) (-0.000000,-0.000000) (0.000000,0.000000) (-0.000000,-0.000000) (0.000000,0.000000) (-0.000000,-0.000005) (-0.000000,-0.000000) (0.000000,0.000000) (0.000000,-0.000000) (-0.000000,0.000000) (0.000000,-0.000000) (-0.000000,0.000007) (0.000000,-0.000111) (-0.000000,-0.000000) (-0.000000,0.000000) (0.000000,-0.000000) (0.000000,0.000001) (-0.000000,-0.000008) (0.000000,0.000130) (-0.000000,-0.002247) (-0.000000,-0.000000) (-0.000000,0.000000) (-0.000000,-0.000001) (0.000000,0.000008) (0.000000,-0.000139) (-0.000000,0.002441) (0.000000,-0.045044) (-0.000000,-0.000000) (-0.000000,0.000000) (-0.000000,-0.000008) (-0.000000,0.000139) (0.000000,-0.002502) (0.000000,0.046875) (-0.000000,-0.916016) (-0.000000,-0.000000) (-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,-0.916016) (-0.000000,19.343750) (0.000000,-426.000000) (0.000000,-0.000000) (0.000000,0.000000) (-0.000000,-0.000000) (0.000000,0.000000) (-0.000000,-0.000002) (0.000000,0.000027) (-0.000000,-0.000000) (0.000000,0.000000) (0.000000,-0.000000) (-0.000000,0.000002) (0.000000,-0.000040) (-0.000000,0.000729) (-0.000000,-0.000000) (-0.000000,0.000000) (0.000000,-0.000003) (0.000000,0.000046) (-0.000000,-0.000872) (0.000000,0.016876) (-0.000000,-0.000000) (-0.000000,0.000002) (-0.000000,-0.000046) (0.000000,0.000919) (0.000000,-0.018402) (-0.000000,0.376953) (-0.000000,-0.000002) (-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.000000) (0.000000,0.000000) (-0.000000,-0.000000) (0.000000,0.000007) (-0.000000,-0.000139) (-0.000000,-0.000000) (0.000000,0.000000) (0.000000,-0.000010) (-0.000000,0.000208) (0.000000,-0.004333) (-0.000000,-0.000000) (-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.000139) (-0.000000,0.004326) (-0.000000,-0.113037) (-0.000000,2.843750) (0.000000,-70.375000) (0.000000,-0.000000) (0.000000,0.000001) (-0.000000,-0.000028) (0.000000,0.000655) (-0.000000,-0.000001) (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.023071) (-0.000000,-0.686523) (0.000000,18.937500) (0.000000,-0.000003) (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)