1
$\begingroup$
mat = 
  Table[
    If[i == j, .5, If[i == j - 1 || i == j + 1, .25, 0]], {i, 1, 100}, {j, 1, 100}];
b = Table[1./i, {i, 1, 100}]; 
old = Table[1, {i, 1, 100}]; 
new = Table[1, {i, 1, 100}]; 
dim = 100;
actual = LinearSolve[mat, b];

I want to find different ways to get the actual value without using the LinearSolve command.

$\endgroup$
3
  • $\begingroup$ You could always use Inverse to compute the inverse of mat, but in most situations LinearSolve is preferable. $\endgroup$ Oct 21, 2019 at 8:11
  • 1
    $\begingroup$ This is just a tridiagonal matrix with constant elements. Analytic solution is available. See here iopscience.iop.org/article/10.1088/0305-4470/29/7/020/meta $\endgroup$
    – yarchik
    Oct 21, 2019 at 9:34
  • $\begingroup$ You can use actual = Inverse[mat].b as Sjoerd Smit has commented. $\endgroup$
    – Sâu
    Oct 22, 2019 at 15:09

1 Answer 1

2
$\begingroup$

I want to find different ways to get the actual value without using the LinearSolve command

You can use Solve

ClearAll[x,i,j];
mat = Table[If[i == j, .5, If[i == j - 1 || i == j + 1, .25, 0]], {i, 1, 100}, {j, 1, 100}];
b = Table[1./i, {i, 1, 100}];

vars = Table[x[i], {i, Length@b}];
eqs = Thread[mat.vars == b];
Solve[eqs, vars]

Mathematica graphics

Compare to

actual=LinearSolve[mat,b]

Mathematica graphics

$\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.