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. JavaWeb -- http-equiv=refresh跳转的时候出现Session 丢失, 解决办法。。

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  2. Codeforces Round #366 (Div. 2) A , B , C 模拟 , 思路 ,queue

    A. Hulk time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

  3. 做一个完整的Java Web项目需要掌握的技能

    最近自己做了几个JavaWeb项目,有公司的商业项目,也有个人做着玩的小项目,写篇文章记录总结一下收获,列举出在做项目的整个过程中,所需要用到的技能和知识点,带给还没有真正接触过完整Java Web项 ...

  4. Python中MySQL插入数据

    sql = 'INSERT INTO course(class_name, credit, properties, teacher_name, college_given, classroom) ' ...

  5. C++初始化小问题

    #include<; } 发现,没有对string进行初始化,就已经默认可以使用,并且是空串,一直用java,对c++不熟悉.搜索了下,发现在c++中,只要对对象进行了定义,如果没有初始化,就会 ...

  6. LINQ(数据查询)

    如果只有空的构造函数,想要对字段进行初始化,可以直接在构造函数后面加上{属性名=值,属性名=值};属性与属性之间用,分割开 //查询所有武学级别大于8的武林高手 //var res = new Lis ...

  7. Codeforces 610D Vika and Segments 线段树+离散化+扫描线

    可以转变成上一题(hdu1542)的形式,把每条线段变成宽为1的矩形,求矩形面积并 要注意的就是转化为右下角的点需要x+1,y-1,画一条线就能看出来了 #include<bits/stdc++ ...

  8. 理解WCF(第一部分,有參考他人)

    依舊不廢話  上乾貨! 1.什么是WCF? WCF全名是:WindowsCommunication Foundation ,是一个运行库和一组 API,用于创建在服务与客户端之间发送消息的系统.它使用 ...

  9. VSCode设置中文语言显示

    Vscode是一款开源的跨平台编辑器.默认情况下,vscode使用的语言为英文(us),如何将其显示语言修改成中文了? 1)打开vscode工具: 2)使用快捷键组合[Ctrl+Shift+p],在搜 ...

  10. Pdf 解密后复制文字乱码

    1.安装cajviewer 这个工具 2.用CAJviewer打开pdf文档 3.选择图像4.点文字识别,这时候就弹窗一个框,里面是可复制的文本,而且准确率比较高