Matlab:Division operators

From Course Wiki
Jump to: navigation, search

Division operators in Matlab=

There are (at least) four different division functions in Matlab: ./, .\, /, and \. These four symbols are shorthand for the Matlab functions: rdivide, ldivide, mrdivide, and mldivide, respectively.

Element-by-element right divide

A ./ B divides each element of matrix A by the corresponding value in matrix B. A and B must be the same size. If either A or B is a scalar, Matlab will expand the argument to be the size of the other argument. The result is a matrix of the same size as A and B. Examples:

Matrix right divide

A / B

Template:Note|Use the element-by-element divide operator (./) instead of the matrix divide operator(/) so that the temperature parameter T can be a vector. If T is a single value, both operators are equivalent. But the / operator will try to do a matrix divide if T is a vector or matrix and give an error since the dimension of the two operands do not match. A for...end loop could also be used to call DnaFraction once for each value of $ T $. But for loops have terrible performance in Matlab and your program will run much faster if you use a vector of $ T $ values instead.}}