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$
  • $\begingroup$ You could always use Inverse to compute the inverse of mat, but in most situations LinearSolve is preferable. $\endgroup$ – Sjoerd Smit Oct 21 '19 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 '19 at 9:34
  • $\begingroup$ You can use actual = Inverse[mat].b as Sjoerd Smit has commented. $\endgroup$ – Sâu Oct 22 '19 at 15:09
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

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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