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

Diag:Diagonal matrices and diagonals of a matrix的更多相关文章

  1. block diagonal matrix 直和 块对角矩阵 不完美 有缺陷 缩放 射影几何

    小结: 1.block diagonal matrix  直和 块对角矩阵 A block diagonal matrix is a block matrix that is a square mat ...

  2. 实用矩阵类(Matrix)(带测试)

    引言: 无意间看到国外一个网站写的Matrix类,实现了加减乘除基本运算以及各自的const版本等等,功能还算比较完善,,于是记录下来,以备后用: #ifndef MATRIX_H #define M ...

  3. sparse matrix

    w https://en.wikipedia.org/wiki/Sparse_matrix 稀疏矩阵存储格式总结+存储效率对比:COO,CSR,DIA,ELL,HYB - Bin的专栏 - 博客园ht ...

  4. codeforce 266c Below the Diagonal 矩阵变换 (思维题)

    C. Below the Diagonal You are given a square matrix consisting of n rows and n columns. We assume th ...

  5. [Matlab] Galois Field arrays

    Operations supported for Galois Field arrays: + - - Addition and subtraction of Galois arrays. * / \ ...

  6. Applying Eigenvalues to the Fibonacci Problem

    http://scottsievert.github.io/blog/2015/01/31/the-mysterious-eigenvalue/ The Fibonacci problem is a ...

  7. HOG(方向梯度直方图)

    结合这周看的论文,我对这周研究的Histogram of oriented gradients(HOG)谈谈自己的理解: HOG descriptors 是应用在计算机视觉和图像处理领域,用于目标检測 ...

  8. python 矩阵分成上三角下三角和对角三个矩阵

    diagonal Return specified diagonals. diagflat Create a 2-D array with the flattened input as a diago ...

  9. [C2P1] Andrew Ng - Machine Learning

    About this Course Machine learning is the science of getting computers to act without being explicit ...

随机推荐

  1. HTTP状态码 304

    HTTP 304 错误Not Modified 客户端有缓冲的文档并发出了一个条件性的请求(一般是提供If-Modified-Since头表示客户只想比指定日期更新的文档).服务器告诉客户,原来缓冲的 ...

  2. JavaScript -- 控制table的创建 与 删除, 排序, 表格颜色

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. Python之print语句Python的注释

    话不多说直接切入正题 print语句可以向屏幕上输出指定的文字.比如输出'hello, world',用代码实现如下: >>> print 'hello, world' 注意: 1. ...

  4. 安装rackspace private cloud --3 Deployment host

    on deploy host: 在deploy host上安装 Ubuntu Server 14.04 (Trusty Tahr) LTS 64-bit # apt-get install aptit ...

  5. Tensorflow搭建神经网络及使用Tensorboard进行可视化

    创建神经网络模型 1.构建神经网络结构,并进行模型训练 import tensorflow as tfimport numpy as npimport matplotlib.pyplot as plt ...

  6. 目标检测 — NMS

    1.非极大值抑制步骤 非极大值抑制算法(Non-maximum suppression,NMS)在目标检测中经常用到.我们的检测算法可能对同一目标产生多次检测的结果,非极大值抑制算法可以保证每个目标只 ...

  7. 51nod 1189 算术基本定理/组合数学

    www.51nod.com/onlineJudge/questionCode.html#!problemId=1189 1189 阶乘分数 题目来源: Spoj 基准时间限制:1 秒 空间限制:131 ...

  8. Django上传文件的两种方式

    基于form表单上传文件 HTML <h3>基于form表单的上传文件</h3> <form action="" method="post& ...

  9. 【SQL查询】查询结果分组_Group

    1. 概述 “Group By”从字面意义上理解就是根据“By”指定的规则对数据进行分组 示例 2. group by的简单操作 3. Group By中Select指定的字段限制 select指定的 ...

  10. 五、python沉淀之路--字典

    一. 1.根据序列,创建字典,并指定统一的值 v = dict.fromkeys(["],222) print(v) {': 222} 2.根据key 获取值,key不存在时,报错:get方 ...