zoukankan      html  css  js  c++  java
  • MTLAB: 稀疏矩阵的表示-sparse

    我们在学习数值算法的过程中,发现像有限差分,谱方法和有限元方法的微分矩阵($ t Differentiation~Matrices$)往往是稀疏的(即非零元素个数为$O(N)$,其中$N$为矩阵的维数)

    $ t SA=sparse(A)=SB-SB^T$

    ----------$ t SB$--------------------------------------------------------------------------------------

    (r,c)      (value)

    (1,2)       2/3
    (1,3)       -1/12
    (2,3)        2/3
    (2,4)        -1/12
    (3,4)        2/3
    (3,5)        -1/12
    (4,5)        2/3
    (1,6)        1/12
    (4,6)        -1/12
    (5,6)        2/3
    (1,7)        -2/3
    (2,7)        1/12
    (5,7)        -1/12
    (6,7)        2/3

    ----------$ t SB^T$--------------------------------------------------------------------------------------

    (2,1)       2/3
    (3,1)        -1/12
    (6,1)       1/12
    (7,1)       -2/3
    (3,2)       2/3
    (4,2)       -1/12
    (7,2)        1/12
    (4,3)        2/3
    (5,3)        -1/12
    (5,4)        2/3
    (6,4)        -1/12
    (6,5)        2/3
    (7,5)        -1/12
    (7,6)        2/3

    $ t SB = sparse(1:N-1,2:N,2/3,N,N)+sparse(1:N-2,3:N,-1/12,N,N)+sparse(1:2,N-1:N,1/12,N,N)+spare(1,N,-2/3,N,N);$

    $ t SA = SB-SB^T.$

    $ t  A=full(SA) .$

    SA与A矩阵在运算中是等价的!A矩阵还可以应用$ t toeplitz()$命令组装.

    思考:假如矩阵A是满的,那么稀疏形式的SA是不是很难输入?

    答案是否定的,注意,在使用$ t spare$时有一个前提条件:非零元素的数量级别必须为$O(N).$ 如果A真是满的, $ t sparse$会很复杂,这时$ t toeplitz()$命令更适合.

  • 相关阅读:
    88. Merge Sorted Array
    87. Scramble String
    86. Partition List
    85. Maximal Rectangle
    84. Largest Rectangle in Histogram
    83. Remove Duplicates from Sorted List
    82. Remove Duplicates from Sorted List II
    81. Search in Rotated Sorted Array II
    80. Remove Duplicates from Sorted Array II
    计算几何——点线关系(叉积)poj2318
  • 原文地址:https://www.cnblogs.com/xtu-hudongdong/p/10756623.html
Copyright © 2011-2022 走看看