2.76 Solve \(A x= b\) and display the solution

Problem: Solve for x given that \(A x=b\) where \[ A=\left ( {\begin {array} [c]{cc}1 & 2\\ 1 & 3 \end {array}} \right ) \] and \[ b=\left ( {\begin {array} [c]{c}5\\ 8 \end {array}} \right ) \]

These 2 equations represent 2 straight lines in a 2D space. An exact solution exist if the 2 lines intersect at a point. The 2 lines are \(x+2y=5\) and \(x+3y=8\).

Mathematica

Remove["Global`*"]; 
ContourPlot[{x+2y==5,x+3y==8}, 
  {x,-3,2}, 
  {y,1.5,4}, 
  ContourStyle->{{Red,Thickness[0.01]}, 
                 {Blue,Thickness[0.01]}}, 
  GridLines->Automatic, 
  GridLinesStyle->Dashed, 
  ImageSize->300]
 

pict

mat = {{1,2},{1,3}}; 
b   = {5,8}; 
x   = LinearSolve[mat,b]
 

{-1,3}
 

 

Matlab

A = [1 2;1 3]; 
b = [5;8]; 
x = A\b
 

x = 
    -1 
     3