next up previous contents
Next: DOTPOWER Element-wise Power Operator Up: Mathematical Operators Previous: DOTRIGHTDIVIDE Element-wise Right-Division Operator   Contents

Subsections

DOTLEFTDIVIDE Element-wise Left-Division Operator

Usage

Divides two numerical arrays (elementwise) - gets its name from the fact that the divisor is on the left. There are two forms for its use, both with the same general syntax:

  y = a .\ b

where a and b are n-dimensional arrays of numerical type. In the first case, the two arguments are the same size, in which case, the output y is the same size as the inputs, and is the element-wise division of b by a. In the second case, either a or b is a scalar, in which case y is the same size as the larger argument, and is the division of the scalar with each element of the other argument.

The type of y depends on the types of a and b using type promotion rules, with one important exception: unlike C, integer types are promoted to double prior to division.

Function Internals

There are three formulae for the dot-left-divide operator, depending on the sizes of the three arguments. In the most general case, in which the two arguments are the same size, the output is computed via:

$\displaystyle y(m_1,\ldots,m_d) = \frac{b(m_1,\ldots,m_d)}{a(m_1,\ldots,m_d)}
$

If a is a scalar, then the output is computed via

$\displaystyle y(m_1,\ldots,m_d) = \frac{b(m_1,\ldots,m_d)}{a}
$

On the other hand, if b is a scalar, then the output is computed via

$\displaystyle y(m_1,\ldots,m_d) = \frac{b}{a(m_1,\ldots,m_d)}.
$

Examples

Here are some examples of using the dot-left-divide operator. First, a straight-forward usage of the .\\ operator. The first example is straightforward:

--> 3 .\ 8
ans = 
  <double>  - size: [1 1]
    2.666666666666667

Note that this is not the same as evaluating 8/3 in C - there, the output would be 2, the result of the integer division.

We can also divide complex arguments:

--> a = 3 + 4*i
a = 
  <complex>  - size: [1 1]
    3.0000000         4.0000000     i  
--> b = 5 + 8*i
b = 
  <complex>  - size: [1 1]
    5.0000000         8.0000000     i  
--> c = b .\ a
c = 
  <complex>  - size: [1 1]
    0.52808988       -0.044943821   i

If a complex value is divided by a double, the result is promoted to dcomplex.

--> b = a .\ 2.0
b = 
  <dcomplex>  - size: [1 1]
    0.240000000000000       -0.320000000000000    i

We can also demonstrate the three forms of the dot-left-divide operator. First the element-wise version:

--> a = [1,2;3,4]
a = 
  <int32>  - size: [2 2]
 
Columns 1 to 2
             1              2  
             3              4  
--> b = [2,3;6,7]
b = 
  <int32>  - size: [2 2]
 
Columns 1 to 2
             2              3  
             6              7  
--> c = a .\ b
c = 
  <double>  - size: [2 2]
 
Columns 1 to 2
    2.000000000000000         1.500000000000000      
    2.000000000000000         1.750000000000000

Then the scalar versions

--> c = a .\ 3
c = 
  <double>  - size: [2 2]
 
Columns 1 to 2
    3.000000000000000         1.500000000000000      
    1.000000000000000         0.750000000000000      
--> c = 3 .\ a
c = 
  <double>  - size: [2 2]
 
Columns 1 to 2
    0.333333333333333         0.666666666666667      
    1.000000000000000         1.333333333333333


next up previous contents
Next: DOTPOWER Element-wise Power Operator Up: Mathematical Operators Previous: DOTRIGHTDIVIDE Element-wise Right-Division Operator   Contents
Samit K. Basu 2005-03-16