Basic functions on matrices

Linear Algebra and the C Language · Wikibooks

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From Wikibooks, under CC BY-SA 4.0, as the source states it. This page at Wikibooks.

    Basic functions on matrices


    Octave commands:
    
    # --------------------------------
    # Copy/Paste into the octave window
    #
      A=[
    +2,+2,+2;
    +3,+3,+3;
    +4,+4,+4];
    #
    A_T = A'
    #
    
    
    # --------------------------------
    # Copy/Paste into the octave window
    #
      A=[
    +2,+2,+2;
    +3,+3,+3;
    +4,+4,+4];
    #
    traceA = trace(A)
    #
    
    
    # --------------------------------
    # Copy/Paste into the octave window
    #
      A=[
    +2,+5,+1;
    +5,-6,-8;
    +1,-8,+5];
    #
    sA = 100.*A
    #
    
    
    # --------------------------------
    # Copy/Paste into the octave window 
    #
      A=[
    +2,+5,+1;
    +5,-6,-8;
    +1,-8,+5];
    #
      B=[
    +2,+5,+1;
    +5,-6,-8;
    +1,-8,+5];
    #
    AB = A*B
    AplusB = A+B
    AminsB = A-B
    #
    
    
    # --------------------------------
    # Copy/Paste into the octave window 
    #
      A=[
    +2,+5,+1;
    +5,-6,-8;
    +1,-8,+5];
    #
    An = A^3
    #
    
    
    # -------------------------------- 
    # Copy/Paste into the octave window
    #
    # A/B  = A*inv(B);
    #
    format short e;
    #
      A=[
    +2,+5,+1;
    +5,-6,-8;
    +1,-8,+5];
    #
      B=[
    +1,+1,+2;
    +5,-3,-5;
    +4,-8,+2];
    #
    AdivB = A/B
    AinvB = A*inv(B)
    #
    
    
    # --------------------------------
    # Copy/Paste into the octave window 
    #
     A=[
    +0.138,+0.626,+0.315,+0.818;
    +0.800,+0.090,+0.658,+0.530;
    +0.777,+0.488,+0.235,-0.150;
    -0.552,+0.097,-0.728,-0.298]
    #
     expm (A)
    #
    
    
    # --------------------------------
    # Copy/Paste into the octave window 
    #
     A=[
    -9,-1,-1,+8,-9;
    -7,-7,-1,+4,+8;
    +6,+6,+4,-7,-5;
    -7,-3,+6,-5,-3;
    -9,-9,+8,-7,-7];
    #
     det(A)
    #
     
     
    # --------------------------------
    # Copy/Paste into the octave window 
    #
     B=[
    +2.00,-7.00,-5.00,-1.00;
    +6.00,+4.00,-5.00,+6.00;
    -3.00,-9.00,+4.00,+4.00;
    -9.00,+4.00,+6.00,+4.00];
    #
    format short e;
    #
     inv(B)
    #
     
    
    # --------------------------------
    # Copy/Paste into the octave window 
    #
     Ab=[
    -325,-601,-801,-221,+360,+524;
    -855,+832,+226,-815,-233,-143;
    +724,-933,-49,-231,-965,-787;
    +290,+238,-905,+772,-327,+446;
    +636,-519,+662,-7,-375,-813];
    #
    format short e;
    #
    rref(Ab,.00000000001)
    # 
     
    
    # --------------------------------
    # Copy/Paste into the octave window 
    #
     a=[
    +2,-9,-1;
    +8,-1,-1;
    -7,-7,+8;
    -1,-7,-9;
    +4,+2,+2];
    #
    format short e;
    #
    [Q, R] = qr (a,0) 
    #
     
     
    # --------------------------------
    # Copy/Paste into the octave window 
    #
     a=[
    +22,+54,+14;
    +54,-67,-83;
    +14,-83,+52];
    #
    format short e;
    #
    EigenValues  = eigs (a,3) 
    #
    
     
    # --------------------------------
    # Copy/Paste into the octave window  
    #
     a=[
    -3,+2,+8;
    +2,+6,-3;
    +8,-1,+2;
    -1,-5,+2;
    -7,+2,-1;
    -9,+6,-1];
    #
    format short e;
    #
    SvdValue = svd (a,10)
    # 
     
    
    # --------------------------------
    # Copy/Paste into the octave window 
    #
     a=[
    -367,+448;
    +448,-847];
    #
    format short e
    #
    [V, E] = eigs (a,2) 
    #
     
    
    # --------------------------------
    # Copy/Paste into the octave window 
    #
     B=[
    +4.00,-3.00,-9.00,+2.00;
    -5.00,-7.00,-9.00,-3.00;
    +8.00,+4.00,-7.00,-5.00;
    +4.00,-5.00,+2.00,-7.00];
    #
    format short e
    #
     [U, S, V] =svd (B,10)
    # 
     
    
    # --------------------------------
    # Copy/Paste into the octave window 
    #
     B=[
    -3.00,+6.00,-9.00;
    -3.00,-1.00,-1.00;
    -9.00,-3.00,-3.00;
    +6.00,-5.00,+6.00;
    -3.00,-1.00,+6.00;
    +8.00,-7.00,-9.00;
    +2.00,-5.00,+2.00;
    -1.00,+6.00,+6.00;
    +8.00,-9.00,+4.00];
    #
    format short e
    #
    pinv(B)
    #