zoukankan      html  css  js  c++  java
  • Diag:Diagonal matrices and diagonals of a matrix

    Diag:Diagonal matrices and diagonals of a matrix 

    Syntax

    X = diag(v,k)

    X = diag(v)

    v = diag(X,k)

    v = diag(X)

    Description

    X = diag(v,k) when v is a vector of n components, returns a square matrix X of order n+abs(k), with the elements of v on the kth diagonal. k = 0 represents the main diagonal, k > 0 above the main diagonal, and k < 0 below the main diagonal. 

    X = diag(v) puts v on the main diagonal, same as above with k = 0. 

    v = diag(X,k) for matrix X, returns a column vector v formed from the elements of the kth diagonal of X. 

    v = diag(X) returns the main diagonal of X, same as above with k = 0.

    example_

    diag([1 2 3],-2)  % 此时k=-2,注意黑色的部分

    ans =

         0     0     0     0     0

         0     0     0     0     0

         1     0     0     0     0

         0     2     0     0     0

         0     0     3     0     0

    diag([1 2 3],2) % 此时k=2,注意黑色的部分

    ans =

         0     0     1     0     0

         0     0     0     2     0

         0     0     0     0     3

         0     0     0     0     0

         0     0     0     0     0

    diag([1 2 3])  % 此时k=0,直接返回对角矩阵

    ans =

         1     0     0

         0     2     0

         0     0     3

    diag([1 2 3;4 5 6; 7 8 9 ]) %若输入矩阵,返回对角

    ans =

         1

         5

         9

  • 相关阅读:
    Matplotlib中柱状图bar使用
    python IDLE颜色设置
    linux报错汇总
    PCA
    高斯混合模型
    深度解剖dubbo源码---01dubbo的架构原理-探索.mp4
    SpringCloud之初识Feign
    第七模块 :微服务监控告警Prometheus架构和实践
    第四模块 :微服务调用链监控CAT架构和实践
    skywalking中文文档
  • 原文地址:https://www.cnblogs.com/qqhfeng/p/5110532.html
Copyright © 2011-2022 走看看