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. nginxif多条件结合判断(实现限速)

    参考文章: https://yq.aliyun.com/articles/44957 需求: 要对某一ip下,使用android客户端的用户进行限速 原理 就是用SET变量进行. AND 就用变量叠加 ...

  2. Java -- JDBC 操作mysql数据库

    1. Demo1 导包时 不要导具体的mysql包, 为了兼容性,导JDBC 中 sql的包既可以了. public class Demo1 { /** * @param args * @throws ...

  3. 解决fasterxml中string字符串转对象json格式错误问题

    软件152 尹以操 springboot中jackson使用的包是fasterxml的.可以通过如下代码,将一个形如json格式string转为一个java对象: com.fasterxml.jack ...

  4. 安装Linux应该知道的十件事

    硬件,软件及其之间的一切 Linux机器的硬件和软件之间一切都由内核主宰. 内核负责硬件和软件的连接,每隔几个礼拜就可以在Internet上获取 更新的内核: 如果你自己安装内核并非易事,这时,就轮到 ...

  5. vlan 配置

    在RedHat上配置vlan: ~]$ modinfo 8021q在ethX接口上配置vlan逻辑子接口: DEVICE=ethX. BOOTPROTO=none ONBOOT=yes IPADDR= ...

  6. mysql数据简单去重

    我有一个 foo 表,定义了如下几个字段:id / a / b,其中 id 是主键,a,b 原本应该具有唯一性, 但因为程序 bug 导致 a,b 内容有重复,现在我要在 a,b 上加唯一索引,请问如 ...

  7. 51nod 1732 LCS变形

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1732 1732 51nod婚姻介绍所 题目来源: 原创 基准时间限制:1 ...

  8. c++primer 第五章编程练习答案

    5.9.1 #include<iostream> int main() { using namespace std; ; cout << "input first i ...

  9. 寻找节点d=n的节点算法

    这里的算法是毕设过程中,自己想到的,也不知道有不有人提出过.这里就记录下发现的过程的具体的算法,以后会用到 背景描述 毕设做的是「社交网络中病毒传播的预测」,前期过程主要是模拟几个网络的数据,然后从一 ...

  10. 加密算法之BLOWFISH算法

    加密信息 BlowFish算法用来加密64Bit长度的字符串. BlowFish算法使用两个"盒"--ungignedlongpbox[18]和unsignedlongsbox[4 ...