[petsc-users] Finding determinant and inverse matrix
Barry Smith
bsmith at mcs.anl.gov
Fri Aug 6 12:46:38 CDT 2010
Sorry for the confusion. PETSc stores the inverse of the diagonal entries (so in the triangular solves it does not need to do divides). Note that 1/26 = .0384615 so all you need to do is invert your result and you'll get the determinant.
Barry
On Aug 6, 2010, at 9:00 AM, Немања Илић (Nemanja Ilic) wrote:
> On Friday 06 August 2010 12:55:19 Немања Илић (Nemanja Ilic) wrote:
>> Hello,
>>
>> For the matrix: 2 -2 0
>> -1 5 1
>> 3 4 5
>> I get determinant = 0.0384615. The correct answer is 26.
>> Maybe I am doing LU Factorization wrong?
>> This is how I do LU Factoring:
>> ierr = MatGetOrdering(Ap, MATORDERING_1WD, &perm, &iperm); CHKERRQ(ierr);
>> ierr = MatFactorInfoInitialize(&info); CHKERRQ(ierr);
>> ierr = MatLUFactor(Ap, perm, iperm, &info); CHKERRQ(ierr);
>>
>> This is the correct LU upper factotrization: 3.000 4.000 5.000
>> 0.000 6.333 2.667
>> 0.000 0.000 -1.368
>> This is what I get: row 0: (0, 0.5) (1, -2) (2, 0)
>> row 1: (0, -0.5) (1, 0.25) (2, 1)
>> row 2: (0, 1.5) (1, 1.75) (2, 0.307692)
>>
>> Thank you,
>> regards,
>> Nemanja
>>
>>
>> On Wednesday 04 August 2010 23:19:37 you wrote:
>>> On Wed, Aug 4, 2010 at 12:18 PM, Немања Илић (Nemanja Ilic) <
>>> nemanja.ilic.81 at gmail.com> wrote:
>>>
>>>> Hello,
>>>>
>>>> Thank you for you previous help. I wrote the code for calculating matrix
>>>> determinant and inverse matrix and they don't break anymore. Still I have
>>>> problems. I try to find determinant in the following way: First get LU
>>>> factor of a matrix and then multiply it's diagonal elements. I don't get
>>>> correct results. Could you tell me wheather the problem
>>>
>>>
>>> That description does not help. What do you get? What is the correct answer?
>>> Did you try it on a small
>>> problem that you can factor by hand?
>>>
>>>
>>>> is maybe in info structure? What information do you need to be able to help
>>>> me? I find the inverse matrix in the following way: I create linear problem
>>>> A * X = B where A is the input matrix, X is the inverse matrix, and B is
>>>> identity matrix. I solve it using MatMatSolve. Could you possibly help me
>>>> and what info do you need?
>>>>
>>>
>>> That should work.
>>>
>>> Matt
>>>
>>>
>>>> Thank you in advance,
>>>> Best regards,
>>>> Nemanja
>>>>
>>>
>>>
>>>
>>
>>
>>
>
>
More information about the petsc-users
mailing list