2
$\begingroup$

When I tried to solve the equation below, I got the $4$ errors. Since I am pretty new on Mathematica, I don't know what I did wrong.

$24x_1+20x_2+16x_3=4$
$20x_1+20x_2+19x_3=36$
$16x_1+19x_2+38x_3=19$

This system is set to solve in Jacobi method after $40$ iterations. Initial approximation is $x_1(0)=0, x_2(0)=0, x_3(0)=0$. I would appreciate it if someone could recommend other methods that I can use for this system!

$\endgroup$

migrated from math.stackexchange.com Jan 24 '14 at 14:48

This question came from our site for people studying math at any level and professionals in related fields.

  • $\begingroup$ Please post your (eventually non working) code $\endgroup$ – Dr. belisarius Jan 24 '14 at 14:51
  • $\begingroup$ Rewrite it in matrix form and use LinearSolve. $\endgroup$ – bill s Jan 24 '14 at 15:20
  • $\begingroup$ Not going to work with Jacobi iterations. The inverse diagonal matrix times coeff matrix - diagonal matrix has two singular values larger than 1. So you don't get convergence. $\endgroup$ – Daniel Lichtblau Jan 24 '14 at 16:42
3
$\begingroup$

Your system is easily solved with Solve. Note the double equal (==), a single equal (=) wont work because it denotes assignment in Mathematica.

Solve[{
  24 x1 + 20 x2 + 16 x3 == 40,
  20 x1 + 20 x2 + 19 x3 == 36,
  16 x1 + 19 x2 + 38 x3 == 19}, 
  {x1, x2, x3}]
{{x1 -> 57/118, x2 -> 349/177, x3 -> -(122/177)}}
$\endgroup$
  • $\begingroup$ The first equation in Solve does not exactly match the OP's equation (40-->4), so the posted result is not correct. $\endgroup$ – Cassini Jan 24 '14 at 22:22
3
$\begingroup$

And if you like to use LinearSolve

eqs={24 x1 +20 x2 + 16 x3 == 4,20 x1 + 20 x2 + 19 x3 == 36,16 x1 + 19 x2 + 38 x3 == 19};
vars = {x1, x2, x3};
mat = CoefficientArrays[eqs, vars];
sol = LinearSolve[mat[[2]], -mat[[1]]]

(* {-(570/59), 2401/177, -(392/177)} *)
$\endgroup$

Your Answer

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