Thursday, June 26, 2014

Transpose - Wikipedia, the free encyclopedia

In linear algebra, the transpose of a matrix A is another matrix AT (also written A′, Atr, tA or At) created by any one of the following equivalent actions:

  • reflect A over its main diagonal (which runs from top-left to bottom-right) to obtain AT
  • write the rows of A as the columns of AT
  • write the columns of A as the rows of AT

Formally, the i th row, j th column element of AT is the j th row, i th column element of A:

[\mathbf{A}^\mathrm{T}]_{ij} = [\mathbf{A}]_{ji}

If A is an m × n matrix then AT is an n × m matrix.


Read full article from Transpose - Wikipedia, the free encyclopedia

Average speed of train - PuzzlersWorld.com

A train is going at a speed of 60kmph towards Delhi and returned back at a speed of 30kmph. What is its average speed?
Average Speed = (Total Distance/Time Taken);
Lets assume the distance traveled by train in one direction is x, and time taken while going towards delhi is t1, while it took t2 time while coming back from Delhi.
We can say
x/t1 = 60
x/t2 = 30
Total Average speed = 2x/(t1 + t2)
average speed = 2x /(x/60+x/30) = (2x/90x)*60*30 = 40
Read full article from Average speed of train - PuzzlersWorld.com

Combinations and Permutations

If the order doesn't matter, it is a Combination.
If the order does matter it is a Permutation.

A Permutation is an ordered Combination.
Permutations
  1. Repetition is Allowed: such as the lock above. It could be "333". n × n × ... (r times) = nr
  2. No Repetition: for example the first three people in a running race. You can't be first andsecond.
Permutations without Repetition
if we wanted to select all: then it's n!.
The factorial function (symbol: !) just means to multiply a series of descending natural numbers. 
if we wanted to select just r, then it's 
where n is the number of things to choose from, and we choose r of them
(No repetition, order matters)

^n\operatorname P_k = n\cdot(n-1)\cdot(n-2)\cdots(n-k+1)

Combinations

Combinations without Repetition

The easiest way to explain it is to:
  • assume that the order does matter (ie permutations),
  • then alter it so the order does not matter

where n is the number of things to choose from, and we choose r of them
(No repetition, order doesn't matter)

 \binom nk = ^n\operatorname C_k = \frac{n(n-1)\ldots(n-k+1)}{k(k-1)\dots1}
So remember, do the permutation, then reduce by a further "r!"
This formula is symmetrical:
In other words choosing 3 balls out of 16, or choosing 13 balls out of 16 have the same number of combinations.

Combinations with Repetition

From http://kruel.co/2012/05/06/number-of-combinations-with-repetition/#sthash.8TnqDEyX.dpbs
There are n = 4 sorts of candy to choose from and you want to buy k = 10 candies. How many ways can you do it?
Note that there are 10 symbols ‘C’ and 3 partition walls, represented by a ‘+’ sign. That is, there are n-1+k = 13, equivalently n+k-1, symbols. Further note that each of the 3 partition walls could be in 1 of 13 positions. In other words, to represent various choices of 10 candies from 4 categories, the positions of the partition walls could be rearranged by choosing n-1 = 3 of n+k-1 = 13 positions
C++CCC+CCCCCC
CCCCCCCCCC+++
We have now translated the original problem into choosing 3 of 13 available positions.
(n+k-1)!/k!(n-1)!

where n is the number of things to choose from, and we choose r of them
(Repetition allowed, order doesn't matter)
Interestingly, we could have looked at the arrows instead of the circles, and we would have then been saying "we have r + (n-1) positions and want to choose (n-1) of them to have arrows", and the answer would be the same ...
Read full article from Combinations and Permutations

Sunday, June 22, 2014

Some Geometric Problems(Algorithms)

Segment intersection: Given two segments, do they intersect?
Intersection and Orientation
Two segments (p1,q1) and (p2,q2) intersect if and only if
one of the following two conditions is verified
• general case:
- (p1,q1,p2) and (p1,q1,q2) have different
orientations and
- (p2,q2,p1) and (p2,q2,q1) have different
orientations
• special case
- (p1,q1,p2), (p1,q1,q2), (p2,q2,p1), and (p2,q2,q1) are
all collinear and
- the x-projections of (p1,q1) and (p2,q2) intersect
- the y-projections of (p1,q1) and (p2,q2) intersect
• Orientation test
- counterclockwise (left turn): σ < τ
- clockwise (right turn): σ > τ
- collinear (left turn): σ = τ
• The orientation depends on whether the expression (y2−y1) (x3−x2) − (y3−y2) (x2−x1)
is positive, negative, or null.
Point Inclusion
• given a polygon and a point, is the point inside or outside the polygon?
• orientation helps solving this problem in linear time
• Draw a horizontal line to the right of each point and extend it to infinity
• Count the number of times a line intersects the polygon. We have:
- even number ⇒ point is outside
- odd number ⇒ point is inside
• What about points d and g ?? Degeneracy!
Simple Closed Path — Part I
• “Connect the dots” without crossings
• Pick the bottommost point a as the anchor point
• For each point p, compute the angle q(p) of the segment (a,p) with respect to the x-axis:
• Traversing the points by increasing angle yields a simple closed path.
• The question is: how do we compute angles?
- We could use trigonometry (e.g., arctan).
- However, the computation would be inefficient since trigonometric functions are not in the normal
instruction set of a computer and need a call to a math-library routine.
- Observation:, we don’t care about the actual
values of the angles. We just want to sort by angle.
- Idea: use the orientation to compare angles
without actually computing them!!
θ(p) < θ(q) ⇔ orientation(a,p,q) = CCW
• We can sort the points by angle by using any
“sorting-by-comparison” algorithm (e.g., heapsort or merge-sort) and replacing angle comparisons with orientation tests
• We obtain an O(N log N)-time algorithm for the simple closed path problem on N points
Graham Scan Algorithm
Algorithm Scan(S, a):
Input: A sequence S of points in the plane beginning
with point a such that:
1) a is a vertex of the convex hull of the points of S
2) the remaining points of S are
counterclockwise around a.
Output: Sequence S from which the points that are
not vertices of the convex hull have been removed.
S.insertLast(a) {add a copy of a at the end of S}
prev ← S.first() {so that prev = a initially}
curr ← S.after(prev) {the next point is on the}
{current convex chain}
repeat
next ← S.after(curr) {advance}
if points (point(prev), point(curr), point(next))
make a left turn then
prev ← curr
else
S.remove(curr) {point curr is on the convex hull}
prev ← S.before(prev)
curr ← S.after(prev)
until curr = S.last()
S.remove(S.last()) {remove the copy of a}
Read full article from GEOMETRIC ALGORITHMS

Ask Dr. Math FAQ: Russian Peasant Multiplication

the Russian peasant algorithm. You don't need multiplication facts to use the Russian peasant algorithm; you only need to double numbers, cut them in half, and add them up. Here are the rules:
  • Write each number at the head of a column.
  • Double the number in the first column, and halve the number in the second column.
       If the number in the second column is odd, divide it by two and drop the remainder.
  • If the number in the second column is even, cross out that entire row.
  • Keep doubling, halving, and crossing out until the number in the second column is 1.
  • Add up the remaining numbers in the first column. The total is the product of your original numbers.
If we multiply 8 * 9, we should get the same answer. Can we explain our answer the same way?
     16  4 
     32  2 
    + 64 
    72 
When we cut 9 in half, we dropped the remainder because 9 is an odd number. Because we have "lost" a one, the product of each row should be smaller from now on. Let's find the difference between the first row and the second row:
    8*9 - 16*4
    = 72 - 64
    = 8.
We can rewrite the subtraction as a sum:
    8 * 9
    = 16 * 4 + 8.
Because our product has decreased by 8, we have to add 8 back in again at the end. 
Read full article from Math Forum: Ask Dr. Math FAQ: Russian Peasant Multiplication

Tuesday, June 17, 2014

Dot Product点积

You can calculate the Dot Product of two vectors this way:
a · b = |a| × |b| × cos(θ)
OR you can calculate it this way:
a · b = ax × bx + ay × by
Three or More Dimensions
a · b = ax × bx + ay × by + az × bz
a · b = |a| × |b| × cos(θ)
两个向量\vec{a} = [a1a2,…, an]和\vec{b} = [b1b2,…, bn]的点积定义为:
\vec{a}\cdot \vec{b} = \sum_{i=1}^n a_ib_i = a_1b_1 + a_2b_2 + \cdots + a_nb_n
使用矩阵乘法并把(纵列)向量当作n×1 矩阵,点积还可以写为:
\vec{a} \cdot \vec{b} = \vec{a} \vec{b}^T
这里的\vec{b}T指示矩阵\vec{b}转置
使用上面的例子,将一个1×3矩阵(就是行向量)乘以一个3×1向量得到结果(通过矩阵乘法的优势得到1×1矩阵也就是标量):
\begin{bmatrix}
 1&3&-5
\end{bmatrix}\begin{bmatrix}
 4\\-2\\-1
\end{bmatrix} = \begin{bmatrix}
 3
\end{bmatrix}

几何解释

在欧几里得空间中,点积可以直观地定义为
 \vec{a} \cdot \vec{b} = |\vec{a}| \, |\vec{b}| \cos \theta \;,
这里 |\vec{x}| 表示\vec{x}(长度),θ表示两个向量之间的角度
注意点积的形式定义和这个定义不同;在形式定义中,\vec{a}\vec{b}的夹角是通过上述等式定义的。
这样,两个互相垂直的向量的点积总是零。若\vec{a}\vec{b}都是单位向量(长度为1),它们的点积就是它们的夹角的余弦。那么,给定两个向量,它们之间的夹角可以通过下列公式得到:
 \cos{\theta} = \frac{\mathbf{a \cdot b}}{|\vec{a}| \, |\vec{b}|}

从定义
 \vec{a} \cdot \vec{b} = a_1 b_1 + a_2 b_2 + a_3 b_3 \;
可以得到定理
 \vec{a} \cdot \vec{b} =  |\vec{a}| |\vec{b}| \cos \theta \;.
为了证明后者是一个和前者等价的定义,需要证明前者可以导出后者。
注意:这个证明采用三维向量,但可以推广到n维的情形。
考虑向量
 \vec{v} = v_1 \vec{i} + v_2 \vec{j} + v_3 \vec{k} \; .
重复使用勾股定理得到
 |\vec{v}|^2 = v_1^2 + v_2^2 + v_3^2 \;.
而根据第二个定义
 \vec{v} \cdot \vec{v} = v_1^2 + v_2^2 + v_3^2 \;,
所以,向量\vec{v}和自身的点积就是其长度的平方。
Please read original article from Dot Product

Labels

Popular Posts