# How to solve this system in matlab?

\begin{align} x_1 &= 20000+0.5x_2+0.1x_3 \\ x_2 &= 40000+0.2x_1+0.6x_3 \\ x_3 &= 20000+0.1x_1+0.25x_2 \end{align} I want to write the system as $Ax=b$, what will then $A$, $b$ and $x$ be? I suppose $x$ should be $[x_1, x_2, x_3]$ but then I must solve for all of the variables?

## Update

Did I formulate the system correctly as $Ax=b$? $$A=\begin{pmatrix} -1 & 0.5 & 0.1 \\ 0.2 & -1 & 0.6 \\ 0.1 & 0.25 & 1 \end{pmatrix}$$ $$b=\begin{pmatrix} -20000 \\-40000 \\-20000 \end{pmatrix}$$ and $$x=\begin{pmatrix} x1 \\ x2 \\x3 \end{pmatrix}$$

## Update 2

I think I got it right, did it this way in matlab:

>> A=[-1 0.5 0.1;0.2 -1 0.6;0.1 0.25 -1]

A =

-1.0000    0.5000    0.1000
0.2000   -1.0000    0.6000
0.1000    0.2500   -1.0000

>> b=[-20000 -40000 -20000]'

b =

-20000
-40000
-20000

>> x=A\b

x =

1.0e+004 *

6.5248
8.1135
4.6809

>>

-
You will need to form $A$ and $b$ by hand. You can then use $x=A/b$ to solve the linear system $Ax=b$. –  Daryl Sep 5 '12 at 11:02
@Daryl Thank you for the comment. I followed your advice so you can inspect my update that I can continue to develop intosomething that I can load into matlab. –  Niklas Rosencrantz Sep 5 '12 at 11:24
Yes, except $A_{33}$ should be $-1$, not $1$. Then / will do the job for you. For help, at the MATLAB prompt, type help mldivide. –  Daryl Sep 5 '12 at 11:37
@Daryl Of course, it should be -1. Now I understand this part and can go on with formulating it in matlab. Thanks for the help. –  Niklas Rosencrantz Sep 5 '12 at 12:13

EDIT: I had the wrong operator. I have updated all operators to \ which is the correct operator to solve $Ax=b$. The operator / solves $A^Tx=b$.

You will need to form $A$ and $b$ by hand. You can then use x=A\b to solve the linear system $Ax=b$.

Your matrix $A$ is almost correct. The $(3,3)$ entry should be $-1$, not 1.

For help with the \ operator, at the MATLAB prompt, type help mldivide.

-
Thank you for the answer. I exercised the solution in matlba and updated the question with the numbers I got that I also could verify fit the equations. So it must be right. –  Niklas Rosencrantz Sep 5 '12 at 14:15

sol1 = inv(A)*b; it's the most simplest question

-
@M-AskmanYou definitely want to use the '\' operator for solving standard linear systems. The use of 'inv()' is rather costly (see example in reference)! mathworks.co.uk/help/techdoc/ref/inv.html –  vanguard2k Sep 5 '12 at 12:06