Saturday 29 August 2015

INVERSE AND ADJOINT OF A MATRIX USING MATLAB

INVERSE OF MATRIX:

matrix inverse can be found out by using the formula

                                               inverse of A = adj(A)/det(A)

adj(A) - adjoint matrix of A

But there is a direct code to find out the Inverse of the matrix

command:
             
               A = [1 4 5; 6 6 8 ; 1 3 7 ]
               B = inv(A)

 the output is


This is how inverse of a matrix can be found.

ADJOINT MATRIX CAN BE FOUND OUT BY

command:  

adj(A) = det(A)*inv(A)

the output is


This is how adjoint matrix can be found 

ROUND,FLOOR,FIX,CEIL COMMANDS

Round:
 Rounds towards nearest integer
COMMANDS:
round(2.3) 
round(2.6)
the output is
  Screenshot (19)

the output of round(2.3) is 2 because the nearest integer for 2.3 is 2
 the output of round(2.6) is 3 because the nearest integer for 2.6 is 3
 Floor:
 it rounds towards negitive infinity code:

floor(2.7)
the output is

  Screenshot (20)

output is 2 because nearest integer in the direction of negitive infinity is 2

 ceil:
        it round towards positive infinity code:
ceil(2.3)
output is

  Screenshot (21)output is 3 because nearest integer in the direction of positive infinity is 3

 fix:
          rounds the number towards zero code:
fix(-1.3) 
fix(1.3)
the output is Screenshot (22) fix(-1.3) gives output -1 because nearest integer in  the direction of zero is -1
 fix(1.3) give s output 1 because nearest integer in the direction of zero is 1
 These are 4 commands to round numbers

DETERMINANT OF A MATRIX USING MATLAB

determinant of a matrix is used to check the singularity
 singular  if det value is 0
non singular if det value is not zero
it is also used to say about invertibility of a matrix

code for determinant:
a = [ 1 5 7 ; 2 3 4 ; 5 7 3] 
det(a)
The output is

  Screenshot (18)

by this we can find the determinant of matrix

TRANSPOSE OF MATRIX USING MATLAB

TRANSPOSE OF MATRIX: ( DONE USING 3 X 3 MATRIX)  

Matrix transpose means Interchanging Rows and columns

 code:
a = [1 2 3 ;4  5  6 ; 7 8 9] 
b = a'                                             ("  '  "  is used for transposing)
output is
  Screenshot (17)

This is how matrix transposing is done

OPERATIONS ON MATRICES USING MATLAB

code for adding two matrices:  ( '+' operator is used for summing two matrices)

a = [ 1 2 3 ; 4 5 6 ; 7 8 9] 
b= [ 1 0 0 ; 0 1 0; 0 0 1] 
c = a+b
Screenshot (14)

code for matrix subtraction: ('-' operator is used for subtraction. It is done using 2x2 matrices)
a = [ 2  2 ; 4  4] 
b = [1   0 ; 0  0] 
c = a-b

Screenshot (15)

multiplying matrices: (' * 'operator is used for multiplication)
a = [ 1  2  ; 3  4 ] 
b = [ 1 0 ; 0  1] 
c = a*b

Screenshot (16)

INTRODUCTION TO MATRICES IN MATLAB

Basics of Matrices Row Matrix  :

row matrix:

a matrix which has only one row.
 example:  [1  2  3]

 column Matrix :

 a matrix which has only one column
 example    [ 1
                      2
                      3 ]

 square matrix:

has equal number of rows and columns

 ex: a=[  2      2
               4     4   ]

 this a 2 x 2 matrix rectangular matrix: matrix which has unequal columns and rows

 ex: a = [2  2  2
              4  4  4 ]

 coding for initializing the each of the above matrices: 

row matrix initializing
a = [1  2  3]                                 (this initilizes a row matrix)
column matrix initializing:
b = [1 ; 2 ; 3]                          (';' is used to end a particular row)
square matrix initializing:
c = [2   2   ;  4   4]
rectangular matrix initializing:
d = [2   2   2 ; 4   4   4]
the output is Screenshot (13)

OPERATION ON VARIABLES IN MATLAB

code for summing of 2 Variables: (write in m- file or commmand window)
a = 10                             (initilizing "a ") 
b =20                               (initilizing "b")
          c = a+b                             ('+' operator is used for summing two  variables')                                        
this is the code used for summing of 2 variables and storing result in variable c the output  is

  Screenshot (10)

Subtraction code:
a=10 
b=5 
c=a-b
the output is

  Screenshot (11)

 multiplying and dividing:
a=10 
b=5  
c=a*b                    ( '*' operator is used for subtraction) 
d=a/b                     (' / ' operator is used for division)
The output is
  Screenshot (12)

the arthematic operation are performed as shown in above examples

INTRO TO VARIABLES IN MATLAB

A Variable is a object that contains a specific value.A variable can be initialized using an "=" operator (assignment operater)
Command:
          a= 10        
       
          % for assigning a integer to a variable

 note: " % " is used to represent comment .The line starting with " % " symbol is skipped from execution output is shown below
  integer

Same syntax applies for decimals
command:
           b= 0.01
the output is


  decimal for

substituting the value in a function
command
c = sin(a)
the output is

  fn

This is how the variables are used in MATLAB

note: as you noticed we didn't put any semicolon after the command as it is popularly used in many programming languages,This is because if we use semicolon it will execute the command but the result is not displayed.

Screenshot (9)

clc command:

"clc " command is used to clear the screen.it is very important command as it is useful everytime

MATLAB INTRODUCTION

Matlab is a is a is a multi-paradigm numerical computing environment and fourth-generation programming language. MATLAB stands for MATRIX LABORATARY. The MATLAB software looks like
  view

We Have write code on m-File. To create m-File click on new script.
  new script

 m-File looks like the image below.Code should be written in the workspace given below in the image
  newscriptfile

after writing the code to execute it click on the run as shown below run

the m-file commands are gonna executed and shows the results on the command window in line to line execution format. we can also directly enter the code in command window without m-file.
  new script
The commands you enter are saved in command history.you can retrieve them at any time.


  commandhistory if

command window isnt present enter "commandhistory" on command window (without " ")

 You can also search for documentation on search box. search

suggestion: enter the code in command window that helps to see what happens for each and every line of code we enters.Disadvantage of using directly in command window is that we cannot save the results.