您的位置:首页 > 编程语言 > MATLAB

matlab program components 之 数组和矩阵

2018-01-28 21:09 405 查看

program components 之 数组和矩阵

matlab 中的数组算数操作符

下面是对 matlab 中的数组运算操作符的一个总结。

操作符 | 作用 | 描述|参考函数|

———|———-|———|—–|

| + | 加 | a + b| plus|

| + | 正| +a|uplus|

| - | 减 | b - a|minus|

| - | 负 | -a | uminus|

| .* | 点乘| a .* b|times|

| .^ | 点乘方 | a .^ b|power|

| ./ | 点右除 | a ./ b |rdivide|

| .\ | 点左除 | a .\ b| ldivide|

| .’ | 点转置 | a.’| transpose|

这里 “点” 的意思是点对点的,也即每个元素对元素的运算。

matlab 中矩阵运算操作符

操作符 | 作用 | 描述|参考函数|

———|———-|———|—–|

| * | 矩阵乘 | a * b| mtimes|

| \ | 矩阵左除 | a\b |mldivide|

| / | 矩阵右除 | a/b |mrdivide|

| ^ | 矩阵乘方 | a^b | mpower |

| ’ | 转置 | a‘|ctranspose|

Compatible Array Sizes For Basic Operations

大部分 matlab 中的二元操作符或者函数都具有兼容性。也就是说,matlab 会对输入其中的参数自动进行隐式拓展以进行相关操作。

这里要注意在旧的版本中提供了 bsxfun 函数用于显式拓展,但是新版本中的操作符已经有自动隐式拓展的功能了。

关系操作符

Symbol | Function Equivalent | Description|

———|———-|———|

| < | lt | less than|

| <= | le | less than or equal to|

| ‘>’ |gt | grater than|

| >= | ge | grater than or equal to|

| == | eq | equal to|

| ~= | ne | not equal to|

注意,上表中的大于号加了单引号这是因为大于在有些版本的 markdown 中有特殊用途,用于单元格合并。加上引号就会避免显示上的问题。

对于复数而言,大于、小于、大于等于、小于等于都是只比较实数部分。而等于和不等于则比较实数和虚数部分。

inf nan NaT and undfined Element Comparisons

inf values are equal to other inf values

nan values are not equal to any numeric value,including other nan values

NaT values are not equal to any other datetime value,including other NaT values.

Undefined categorical elements are not equal to any other categorical value,including other undefined elements.

matlab 中运算符的优先级

Parentheses ()

Transpose (.’), power (.^), complex conjugate transpose (‘), matrix power (^)

Power with unary minus (.^-), unary plus (.^+), or logical negation (.^~) as well

as
4000
matrix power with unary minus (^-), unary plus (^+), or logical negation (^~).

Note: Although most operators work from left to right, the operators (^-), (.^-),

(^+), (.^+), (^~), and (.^~) work from second from the right to left. It is

recommended that you use parentheses to explicitly specify the intended precedence

of statements containing these operator combinations.

Unary plus (+), unary minus (-), logical negation (~)

Multiplication (.*), right division (./), left division (.), matrix multiplication

(*), matrix right division (/), matrix left division ()

Addition (+), subtraction (-)

Colon operator (:)

Less than (<), less than or equal to (<=), greater than (>), greater than or equal to

(>=), equal to (==), not equal to (~=)

Element-wise AND (&)

Element-wise OR (|)

Short-circuit AND (&&)

Short-circuit OR (||)

总结

其中关于 tolerance 的一节没有看懂,以后等有需要再研究。还有由于 markdown 解析器的问题,在 csdn 中显示有一定问题,请谅解。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: