0
$\begingroup$

I have just started with PETSc hence it might seem like a very stupid question but I couldn't find any answer in manual. After Calling KSPSolve, where can I access the soluition for my linear system? Example for a matrix:

$$ \left(\begin{array}{ccc} 2 &-1 & 0\\ -1 &2&-1\\ 0&-1&2 \end{array}\right) \left(\begin{array}{c} x\\y\\z \end{array}\right)= \left(\begin{array}{c} 1\\0\\1 \end{array}\right) $$

I want to get vector $$ \left(\begin{array}{c} 3/4\\1/2\\1/4 \end{array}\right) $$ back. The documentation for KSP Solve says x - the solution (this may be the same vector as b, then b will be overwritten with answer)

but I keep getting x vector as $$ \left(\begin{array}{c} 1\\1\\1 \end{array}\right) $$

Is there something wrong in my understanding?

$\endgroup$
2
  • 3
    $\begingroup$ The solution to that (nonsingular) linear system is $[1, 1, 1]^T$. I don't understand why you want to get a vector that is not a solution. $\endgroup$
    – Jed Brown
    Commented Sep 13, 2018 at 15:30
  • $\begingroup$ Because I am that idiot who solved the equations wrong :| and assumed I am not able to get results $\endgroup$
    – ipcamit
    Commented Sep 13, 2018 at 18:28

1 Answer 1

0
$\begingroup$

Before you solve the system in PETSc you store the matrix $A$ and RHS $b$. The message from PETSc says, that after the system is solved, the solution might be overwritten into $b$, where originally the RHS was stored. That's what it means.

For the original system of equations:

$$ \left(\begin{array}{ccc} 2 &-1 & 0\\ -1 &2&-1\\ 0&-1&2 \end{array}\right) \left(\begin{array}{c} x\\y\\z \end{array}\right)= \left(\begin{array}{c} 1\\0\\1 \end{array}\right) $$ the correct solution is indeed (as pointed out by @JedBrown) $$ \left(\begin{array}{c} 1\\1\\1 \end{array}\right) $$

If you intend (for whatever good reason) to get $$ \left(\begin{array}{c} 3/4\\1/2\\1/4 \end{array}\right) $$ that only means that you have a typo in either your matrix or RHS. Assuming that your matrix is correct, you will get your desired solution for the following system (changed RHS slightly): $$ \left(\begin{array}{ccc} 2 &-1 & 0\\ -1 &2&-1\\ 0&-1&2 \end{array}\right) \left(\begin{array}{c} x\\y\\z \end{array}\right)= \left(\begin{array}{c} 1\\\color{red}{1/2}\\1 \end{array}\right) $$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.