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. Spring获取bean的一种方式

    随便一百度,网上一大把,并且还不止一种.所以这里就只记录目前用的一种好了. 实现ApplicationContextAware接口 即可: import org.springframework.bea ...

  2. Flume-NG源码阅读之HDFSEventSink

    HDFSEventSink是flume中一个很重要的sink,配置文件中type=hdfs.与此sink相关的类都在org.apache.flume.sink.hdfs包中. HDFSEventSin ...

  3. linux下图形字符的命令

    banner sudo apt-get install sysvbanner banner song 若更改字体可以使用banner song printerbanner -w 50 A toilet ...

  4. 搭建svn服务器小结

    最开始是用VisualSVN-Server来搭建服务器的,某一天安装了eset杀毒软件后,发现不能用了,每次打开配置页时报错.Visualsvn server 0x80070005 百度搜索,找到相同 ...

  5. web自动化:前端页面组成

    一.web页面的组成 1. 常用:HTML + CSS + Javascript 2. HTML:定义页面的呈现内容 3. CSS:Cascading Style Sheets,层叠样式表 控制你的网 ...

  6. Kestrel Web 服务器学习笔记

    前言: ASP.NET Core 已经不是啥新鲜的东西,很多新启的项目都会首选 Core 做开发: 而 Kestrel 可以说是微软推出的唯一真正实现跨平台的 Web 服务器了: Kestrel 利用 ...

  7. 去掉标题栏的方法(使用requestWindowFeature(Window.FEATURE_NO_TITLE);为什么失效?不仅失效,可能会挂)

    使用requestWindowFeature(Window.FEATURE_NO_TITLE)隐藏标题栏失效的原因,不仅失效,可能会挂.可能是activity继承的是AppCompatActivity ...

  8. DocString

    文档字符串:写注释专用的, 在函数的第一个逻辑行的字符串是这个函数的 文档字符串 .注意,DocStrings也适用于模块和类,我们会在后面相应的章节学习它们. 文档字符串的惯例是一个多行字符串,它的 ...

  9. redis_学习_02_redis 可视化工具 Redis Desktop Manager

    二.参考资料 1.Redis可视化工具Redis Desktop Manager使用 2.超好用的Redis管理及监控工具,使用后可大大提高你的工作效率!

  10. github提交代码时遇到”Everything up-to-date“问题的解决方式

    需要创建一个新分支,将最新代码加入新分支, 再将新分支合并到主分支,然后提交主分支代码到github网站. ---------------------------------------------- ...