[petsc-users] question about the PetscFVLeastSquaresPseudoInverseSVD

Rongliang Chen rongliang.chan at gmail.com
Wed Mar 30 10:41:50 CDT 2016


Hi Jed,

Many many thanks for your help!

Best regards,
Rongliang

On 03/29/2016 08:12 PM, Jed Brown wrote:
> Rongliang Chen <rongliang.chan at gmail.com> writes:
>
>> -----------------------------------
>> Initialize the matrix A (is a 3 x 3 matrix):
>> 1.000000 0.000000 0.000000
>> 0.000000 1.000000 0.000000
>> 0.000000 0.000000 1.000000
>>
>> Initialize the matrix B:
>> 1.000000 0.000000 0.000000
>> 0.000000 1.000000 0.000000
>> 0.000000 0.000000 1.000000
>>
>> The output of the SVD based least square:
>> 0.500000 0.000000 -0.500000
>> 0.500000 0.000000 -0.500000
>> 0.000000 0.000000 1.000000
> So the above looks like a problem.  Let's see how that matrix is
> constructed.
>
>>    ierr = PetscPrintf(PETSC_COMM_WORLD,"Initialize the matrix A (is a %d x %d matrix):\n", n, m);
>>    /* initialize to identity */
>>    for (j=0; j<n; j++) {
>>      for (i=0; i<m; i++) {
>>        if (i == j) {
>>          A[i + j*m] = 1.0;
>>        }else{
>>          A[i + j*m] = 0.0;
>>        }
>>        PetscPrintf(PETSC_COMM_WORLD,"%f ", A[i + j*m]);
> It's a packed 3x3 matrix (lda=3).
>
>>    ierr  = PetscBLASIntCast(mstride,&lda);CHKERRQ(ierr);
> And yet mstride=4, so your matrix is not packed correctly.  If you're
> not familiar with BLAS-style packing with lda, please read the
> documentation.
>
>>    LAPACKgelss_(&M,&N,&nrhs,A,&lda,Brhs,&ldb, (PetscReal *) tau,&rcond,&irank,tmpwork,&ldwork,&info);
> If you use A[i + j*mstride] when filling in the entries above, the
> program outputs the following.
>
> maxNumFaces = 4, worksize = 75
> -----------------------------------
> Initialize the matrix A (is a 3 x 4 matrix):
> 1.000000 0.000000 0.000000 0.000000
> 0.000000 1.000000 0.000000 0.000000
> 0.000000 0.000000 1.000000 0.000000
>
> Initialize the matrix B:
> 1.000000 0.000000 0.000000 0.000000
> 0.000000 1.000000 0.000000 0.000000
> 0.000000 0.000000 1.000000 0.000000
> 0.000000 0.000000 0.000000 1.000000
>
> The output of the SVD based least square:
> 1.000000 0.000000 0.000000 0.000000
> 0.000000 1.000000 0.000000 0.000000
> 0.000000 0.000000 1.000000 0.000000
>
> -----------------------------------
> Initialize the matrix A (is a 3 x 4 matrix):
> 1.000000 0.000000 0.000000 0.000000
> 0.000000 1.000000 0.000000 0.000000
> 0.000000 0.000000 1.000000 0.000000
>
> Initialize the matrix B:
> 1.000000 0.000000 0.000000 0.000000
> 0.000000 1.000000 0.000000 0.000000
> 0.000000 0.000000 1.000000 0.000000
> 0.000000 0.000000 0.000000 1.000000
>
> The output of the SVD based least square:
> 1.000000 0.000000 0.000000 0.000000
> 0.000000 1.000000 0.000000 0.000000
> 0.000000 0.000000 1.000000 0.000000
>
> -----------------------------------
> Initialize the matrix A (is a 3 x 3 matrix):
> 1.000000 0.000000 0.000000
> 0.000000 0.000000 1.000000
> 0.000000 0.000000 0.000000
>
> Initialize the matrix B:
> 1.000000 0.000000 0.000000
> 0.000000 1.000000 0.000000
> 0.000000 0.000000 1.000000
>
> The output of the SVD based least square:
> 1.000000 0.000000 0.000000
> 0.000000 1.000000 0.000000
> 0.000000 0.000000 1.000000
>
> -----------------------------------
> Initialize the matrix A (is a 3 x 3 matrix):
> 1.000000 0.000000 0.000000
> 0.000000 0.000000 1.000000
> 0.000000 0.000000 0.000000
>
> Initialize the matrix B:
> 1.000000 0.000000 0.000000
> 0.000000 1.000000 0.000000
> 0.000000 0.000000 1.000000
>
> The output of the SVD based least square:
> 1.000000 0.000000 0.000000
> 0.000000 1.000000 0.000000
> 0.000000 0.000000 1.000000
>
> -----------------------------------
> Initialize the matrix A (is a 3 x 2 matrix):
> 1.000000 0.000000
> 0.000000 0.000000
> 0.000000 1.000000
>
> Initialize the matrix B:
> 1.000000 0.000000 0.000000
> 0.000000 1.000000 0.000000
> 0.000000 0.000000 1.000000
>
> The output of the SVD based least square:
> 1.000000 0.000000
> 0.000000 1.000000
> 0.000000 0.000000
>
> -----------------------------------
> Initialize the matrix A (is a 3 x 2 matrix):
> 1.000000 0.000000
> 0.000000 0.000000
> 0.000000 1.000000
>
> Initialize the matrix B:
> 1.000000 0.000000 0.000000
> 0.000000 1.000000 0.000000
> 0.000000 0.000000 1.000000
>
> The output of the SVD based least square:
> 1.000000 0.000000
> 0.000000 1.000000
> 0.000000 0.000000
>



More information about the petsc-users mailing list