TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

MATLAB Linear Algebra

MATLAB Linear Algebra with MATLAB Tutorial, MATLAB, MATLAB Introduction, MATLAB Installation, MATLAB Platform, MATLAB Syntax, MATLAB Data Types, MATLAB Variables, MATLAB Operators, MATLAB Commands, MATLAB Loops, MATLAB Strings, MATLAB Numbers, MATLAB Vectors, MATLAB Downloading etc.

<< Back to MATLAB

Linear Algebra

Solving a Linear System

A linear algebraic equation is an equation of the system

a1 x1+a2 x2+a3 x3+⋯+an xn=b

where a's are constant coefficients, the x's are the unknowns, and b is a constant. A solution is a sequence of numbers s1,s2, and s3that satisfies the equation.

Example

4x1+5x2-2x3=16

is such an equation in which there are three unknown: x1,x2,andx3. One solution to this equation is x1=3,x2=4 and x3=8,since 4*3+5*4-2*8 is equal to 16.

A system of a linear algebraic equation is a set of the equation of the form:

a11 x1+a12 x2+a13 x3+⋯+a1n xn=b1
a21 x1+a22 x2+a23 x3+⋯+a2n xn=b2
a31 x1+a32 x2+a33 x3+⋯+a3n xn=b3
am1 x1+am2 x2+am3 x3+⋯+amn xn=bm

This is called an m*n system of equations; there are m equations and n unknowns.

Matrix Forms

Because of the method that matrix multiplication works, these equations can be defined in the matrix form as Ax = b where A is the matrix of the coefficients, x is the column vector of the unknown, and b is a column vector of the constant from the right-hand side of the equations:

A           x      =       b
a11 a12 a13...a1n       x1       b1
a21 a22 a23...a2n       x2       b2
a31 a32 a33...a3n       x3       b3
.............................       .............       ........
am1 am2 am3...amn       xn       bm

A solution set is a set of all possible solutions to the system of equation (all sets of value for the unknowns that solve the equation). All systems of linear equations have either:

  • No solutions
  • One solution
  • Infinitely many solutions

Solution using matrix Inverse

Probably the simple way of solving this system of equations is to use the matrix inverse.

A-1 A=1

We can multiply both sides of the matrix equation AX= B by A-1to get

A-1 AX=A-1 B

Or

X=A-1 B

So, the solution can be found as a product of the inverse of A and the column vector b.

In MATLAB, there are two method of doing this, using the built-in inv function and matrix multiplication, and also using the "\" operator:

>> A = [3 4 1; -2 0 3; 1 2 4]	
A =
        3     4      1
      -2      0      3
       1      2      4	
>> b = [2 1 0]'	
     b =
          2
         1
         0  
 >> x = inv(A) * b
x =
       -1.1818
        1.5000
       -0.4545
>> A\b
ans =
      -1.1818
       1.5000
       -0.4545

Solving 2x2 Systems of Equations

The simplest system is a 2 x 2 system, with just two equations and two unknowns. For these systems, there is a simple definition for the inverse of a matrix, which uses the determinant D of the matrix.

For a coefficient matrix, A generally defined as

Linear Algebra

the determinant D is defined as a11 a22-a12 a21

Linear Algebra

Example

          x1+3x2=-2
          2x1+4x2=1

This would be written in matrix form as

Linear Algebra

The determinant D = 1*4 -3*2 = -2.

Linear Algebra

MATLAB has built-in functions det to find the determinant of the matrix.

>> A = [1 3; 2 4]
A =
         1      3
         2      4
>> b = [-2;1]
b =
        -2
         1
>> det(A)
ans =
          -2
>> inv(A)
ans =
         -2.0000     1.5000
          1.0000     -0.5000
>> x = inv(A) * b
x =
      5.5000
    -2.5000





Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf