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. DS 和【ADDRESS】学习记录

    CPU要读写一个内存单元的时候,必须先给出这个内存单元的地址. 内存单元由2部分组成. 8086CPU中,内存地址由以下组成. 1:段地址 2:偏移地址 8086CPU中,有一个DS寄存器地址,通常用 ...

  2. linux-RabbitMQ安装命令

    一.RabbitMQ 1.安装配置epel源    $ rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.no ...

  3. review35

    使用Thread创建线程通常使用的方法是:Thread(Runnable target).该构造方法中的参数是一个Runnable类型的接口,因此在创建线程对象时必须向构造方法的参数传递一个实现Run ...

  4. 安全清空废纸篓mac

    在.bash_profile中加入: alias secureempty='sudo srm -rfvsz /Volumes/*/.Trashes/* ~/.Trash/*' 然后做终端输入:secu ...

  5. spring boot + thymeleaf 报错 org.thymeleaf.exceptions.TemplateInputException

    org.thymeleaf.exceptions.TemplateInputException: Error resolving template "admin/verifyPassword ...

  6. nginx默认语法

    vi /etc/nginx/nginx.conf user 设置nginx服务的系统使用用户worker_processes 工作进程数error_log nginx的错误日志pid nginx服务启 ...

  7. JavaScript中的数组和对象 增删遍

    由于 JavaScript 的语言特性,我们可以向通用对象动态添加和删除属性.所以 Object 也可以看成是 JS 的一种特殊的集合. 虽然这个集合的 key 只能是 String 类型,不像 Ja ...

  8. Data、String、Long三种日期类型之间的相互转换

    // date类型转换为String类型 // formatType格式为yyyy-MM-dd HH:mm:ss//yyyy年MM月dd日 HH时mm分ss秒 // data Date类型的时间 pu ...

  9. DataTable的用法

    在项目中经常用到DataTable,如果DataTable使用得当,不仅能使程序简洁实用,而且能够提高性能,达到事半功倍的效果,现对DataTable的使用技巧进行一下总结. 一.DataTable简 ...

  10. 《领域驱动设计 C# 2008 实现》 - 书摘精要

    (P2) 智能客户反模式被 Eric Evans 定义为“把所有业务逻辑放进用户界面.把系统分解成小函数,作为分离的用户界面实现,并在里面嵌入业务规则.使用关系数据库作为共享的数据仓储.使用现有的自动 ...