haibaraxx的个人博客分享 http://blog.sciencenet.cn/u/haibaraxx

博文

Matlab: operations for matrix

已有 1806 次阅读 2016-3-8 04:44 |个人分类:Matlab|系统分类:科研笔记| for, Matrix, operations

A = [1 2 3; 4 5 6];

A1 = [1, 2, 3; 4, 5, 6];    % A1 is exactly the same with A.

C = [2 3 4; 6 8 9];

D=[1 1; 1 2];

% transposition

Syntax: B = A'

Output: [1 4; 2 5; 3 6]

% the inverse of the square matrix D.

D_inv = inv(D);  

% multiplication
A_C= A.*C;     % give the entry-by-entry product with corrsponding elements of each mateix multiplied. Note that size(A)=size(C).i.e.[2 6 12; 24 40 54]
AB = A*B;     % [14 32; 32 77]

% division

a=2;

b=10;

% backslash: a is divided by b

Syntax: a/b  

Output: 0.2

Then you know A./C! % entry-by-entry division

% forward slash: b is divided by a

Syntax: ab  

Output: 5

Then you know A.C! % entry-by-entry division

% exponentiation

Syntax: A.^C % entry-by-entry exponentiation

Output: [1 8 81; 4096 390625 10077696]

Syntax: D^2 % the same as D*D. It must be square matrix!

% addition &subtraction

Syntax: A+2 % entry-by-entry addition

Output: [3 4 5; 6 7 8]

Syntax: A-2 % entry-by-entry subtraction

Output: [-1 0 1; 2 3 4]





 





https://blog.sciencenet.cn/blog-3031432-961142.html

上一篇:Python 2: open a webpage
下一篇:Matlab: indexing
收藏 IP: 134.1.1.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-7-17 21:36

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部