# Matrix and simulation

I came across a simulation software called MATLAB. I got to know it takes inputs in the form of matrices, provides output in terms of matrices , all in all it operates using matrices. But it seems pretty weird to me that it uses matrices. Why does it use matrices? How does usage of matrices makes it efficient ?

-
This sounds like a mathematics question, not an electrical engineering question. – Phil Frost Jan 16 '13 at 15:52
@PhilFrost But completely related to electrical and electronics engineering, as people in that field use it regularly. – Primeczar Jan 16 '13 at 15:56
Sure, there's hardly an engineering field that isn't related to mathematics. In any case, many mathematicians use MATLAB, but I doubt many electrical engineers use it, since there are simulation tools (like SPICE) more suited to electronics problems. It would be in your interest to ask this question on a mathematics forum. – Phil Frost Jan 16 '13 at 16:01
@PhilFrost Honestly, every EE coming out of school currently should be learning matlab, it is major in the DSP field/communications field and we used it for some practice simulations in EM. Barring that, how does using matrices make it efficient seems like a CS question. I have no idea why they coded it that way, but the way they coded it make all of your code use matrix math or wait months for your script to run. – Kortuk Jan 16 '13 at 16:07
If the only tool you have is Matlab everything looks like a matrix. – Curd Jan 17 '13 at 11:01

Key point: Matlab is not a simulation tool that uses matrices. It is a matrix math tool that is often used to simulate things.

It is or can be also used for all kinds of other calculations that can be done in terms of matrices --- this includes statistics, linear programming (systems optimization), curve fitting, etc.

The reason we use matrices to do simulations (and lots of other kinds of calculations) is because it provides a very compact way to write down large sets of equations in linear algebra. A single matrix equation like

$\mathbb{A}\bar{x} = \bar{b}$

can, in a single line, represent an arbitrary number of algebraic equations with an arbitrary number of terms each, as long as those equations meet some simple requirements.

Also, these linear algebra equations can be solved by simple but repetitive operations, which is exactly what computers are good out.

Luckily we were able to figure out how to simulate physical systems using linear algebra, so that we can use this notation and computer processes to predict the behavior of different things we want to build (circuits, buildings, chemical plant control systems, ...)

-
Someone give me a couple more examples of matrix calculations that aren't simulations? – The Photon Jan 16 '13 at 17:03
basis vector fitting for curve fitting, wavelet analysis, etc. – placeholder Jan 16 '13 at 17:35
calculation of eigenvalues? – Scott Seidman Jan 16 '13 at 21:38
Your statement about 'A single equation like "A x = b...' is a bit confusing. It might be clearer to say "If one represents equations as rows on a matrix, operations on those equations can be expressed as operations on matrices." and offer an example, e.g. the equations "2x+3y=14" and "2x-3y=4" can be represented as [2 3 16] and [2 -3 4]. Adding corresponding items yields [4 0 20]; dividing all items by 4 yields [1 0 5]. Turning that back into an equation yields "1x + 0y = 5", which can easily be solved for x. – supercat Jan 16 '13 at 22:58
@supercat, I knew I was going to have to come back and clean that up. But I don't want to make this a tutorial on linear algebra. I reworded it, and also used MathJax to set off the matrix/vector equation --- do you think it's more clear now? – The Photon Jan 16 '13 at 23:22

Matrices are extremely important in engineering and science. All circuit analysis uses them in the form of either state-space formulation or Kirchhoff's circuit laws. SPICE is based on Kirchhoff's current law (KCL) and uses matrix method to solve the KCL equations.

If you wanted to play around with matrices you could (in addition to MatLab) look at SciLab ( http://www.scilab.org/ ) or Octave ( http://www.gnu.org/software/octave/ ) . SciLab has a system modelling tool called Xcos that has modelica extensions, so can be used for circuit modelling.

It is also interesting that Kirchhoff's laws can be generalized to any lumped element system; like thermal, mechanical, and pneumatic by identifying appropriate across and through variables. For example, electrical across and through variables are Voltage and current.

-

The system of linear algebra using matrices can be used for solving PDE's (Partial Differential Equations) of which engineering is full of, amongst other things. There are certain operations in matrix math that correspond to operations in the solutions of PDE's, like decomposition, LDU, Cholesky (Spelling?). Least squares fitting and doing symbolic math. The applications of Linear algebra are far from linear themselves.

-