13.11: Matrix Addition and Subtraction

Fundamentals of MATLAB Programming · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    Read aloud

    How

    Speed: 1×
    Light up
    Highlight

    Symbols: Mulberry Symbols, © 2018–2026 Steve Lee, CC BY-SA 4.0 (licence, the set), the site's own copies.

    From LibreTexts, under CC BY-NC-SA, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    13.11: Matrix Addition and Subtraction

    Matrices can be added or subtracted only if they have the same dimensions. MATLAB performs addition and subtraction element by element.

    Example \(\PageIndex{1}\)

    Adding and subtracting two matrices.

    A = [3 2 2; 6 4 8];
    
    B = [5 4 3; 6 6 6];
    
    
    
    C = A + B
    
    D = A - B
    Solution
    C =
    
        8    6    5
       12   10   14
    
    D =
    
      -2  -2  -1
       0  -2   2

    If the dimensions of the two matrices do not match, MATLAB will return an error.

    Example \(\PageIndex{2}\)

    When the dimensions do not match.

    A = [3 2 2; 6 4 8];
    
    B = [5 4; 6 6];
    
    
    
    C = A + B
    
    D = A - B
    Solution
    error: operator +: nonconformant arguments (op1 is 2x3, op2 is 2x2)
    error: operator -: nonconformant arguments (op1 is 2x3, op2 is 2x2)

    This page titled 13.11: Matrix Addition and Subtraction was last modified on Tue, 30 Jun 2026 02:11:59 GMT and is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Zara Noroozi.