Algorithm concerning orthogonal matrices - algorithm

Say I have a n-dimensional orthogonal matrix, with some of its elements given and these others unknown. Does there exist an effective algorithm to find out the unknown elements and restore the whole matrix (it only needs to find one solution if there are many, and gives an error when no solution exists)?
Thanks!

Solution depends on how many element per row/column is missing.
I can see two ways how to approach this
1. max 1 element missing per row/column
in this case you can exploit that any row / column of orthogonal matrix is unit vector
so for any row/column { a1,a2,a3=??,a4,...,an }
the unknown element is a3=sqrt(1-a1^2-a2^2-a4^2-a5^2-...-an^2)
if you have more then one unknown elements in row use column and vice versa
if there is too many unknowns in row and columns at the same time
then you need to use different approach for that element
2. more then 1 missing element
first find all unknowns that can be found by approach 1
then you can exploit that Inverse(Q)==Transpose(Q) if Q is orthogonal
so derive algebraic formula per unknown element from inverse Q
and compare it to transposed one
this will create one linear equation
do this for all unknowns and solve the system
a11 a12 a13
Q = a21 a22=?? a23=??
a31 a32=?? a33=??
a11 a21 a31
transpose(Q) = a12 a22=?? a32=??
a13 a23=?? a33=??
i11 i12 i13
inverse(Q)= i21 i22 i23
i31 i32 i33
det=a11.a22.a33+a21.a32.a13+a31.a12.a23-a11.a32.a23-a31.a22.a13-a21.a12.a33
a22=i22=(a11.a33-a13.a31)/det
a32=i23=(a13.a21-a11.a23)/det
a23=i32=(a12.a31-a11.a32)/det
a33=i33=(a11.a22-a12.a21)/det
this should be solvable ...
if not then you can also add equations from bullet 1
if still not then either solution cant be found or you need to use different approach
Before computing you should check first if the |elements| are not too big
so sum all the known elements^2 in row/column and the result should be <=1
if not then this is nor orthogonal matrix ...
for more info see Orthogonal matrixes (Wiki)
3. if you have element=1.0
then all elements in that row/column will be zero

Related

Indexing and retrieving data using index for a 3D grid for interpolation in c++

I have a 3D Cartesian grid data that needs to be used to create a 3D regular mesh for interpolation method. x,y & z are 3 vectors with data points that are used to form this grid. My question is, how can i efficiently give 2 index to these points say,
where c000 is indexed as 1 point (1,1,1), c100 is indexed as 2 for (2,1,1) for (x,y,z)
coordinate points and another index to identify the 8 points forming the cube. Say if I have a point C, I must retrieve the nearest 8 points for interpolation. so for points c000,c100,c110,c010,c001,c101,c111,c011 point index and cube index. Since the data available is huge, the focus is to use faster implementation. pls give me some hints on how to proceed.
About the maths:
Identifying the cube which a point p surrounds requires a mapping
U ⊂ ℝ+**3 -> ℕ:
p' (= p - O_) -> hash_r(p');
"O_" being located at (min_x(G),min_y(G),min_z(G)) of the Grid G.
Along each axis, the cube numbering is trivial.
Given a compound cube number
n_ = (s,t,u)
and N_x, N_y, N_z being the size of your X_, Y_, Z_, a suitable hash would be
hash_n(n_) = s
| t * 2**(floor(log_2(N_x))+1)
| u * 2**(floor(log_2(N_x)) + floor(log_2(N_y)) + 2).
To calculate e.g. "s" for a point C, take
s = floor((C[0] - O_)/ a)
"a" being the edge length of the cubes.
About taking that to C++
Given you have enough space to allocate
(2**(floor(log_2(max(N_x, N_y, N_z)))+1)**3
buckets, a std::unordered_map<hash_t,Cube> using that (perfect) hash would offer O(1) for finding the cube for a point p.
A lesser pompous std::map<hash_t,Cube> using a less based on that hash would offer O(log(N)) find complexity.

About the derivation of a composite quaternion

This problem has been bothering me for several days, hence I decided to ask you for help.
I am reading the book "Quaternions and Rotation Sequence" written by Jack B. Kuipers. In section 6.4, the author derives a formula of a composite rotation quaternion. One of the steps of this derivation is difficult for me to understand.
I would like to briefly describe the derivation process as follow:
Consider a tracking problem as in this picture.
(I am sorry I have to use links instead of posting pictures directly because this is the first time I post a question here so I am not eligible to do so yet)
In the picture, XYZ is a global, reference frame. 2 successive rotations are performed:
The first one is a rotation about the Z axis through an angle alpha, transforming frame XYZ into a new frame x1y1z1.
The second one is a rotation about the y1 axis through an angle beta, transforming frame x1y1z1 into a new frame x2y2z2.
The goal is to find a single composite rotation quaternion which is equivalent to the two rotations above.
The author does this as follow. The first rotation can be represented by the following quaternion p:
p = cos(alpha/2) + k*sin(alpha/2) (1)
In this formula, k is a standard basis vector (we have vectors i, j, k in R3 corresponding to the axes x, y, z respectively).
The second rotation can be represented by the following quaternion q:
q = cos(beta/2) + j*sin(beta/2) (2)
The composite quaternion we are looking for is the product of these 2 quaternions: qp. The formula of this product is in this picture.
In order to derive this final formula, the author uses 2 assumptions about the standard basis vectors i, j, k, which are: k.j = 0 and k x j = -i. And this is where I dont understand.
We all know that, for a set of 3 mutually orthogonal vectors i, j, k, these 2 assumptions above are correct. However, vector k in (1) and vector j in (2) don't belong to the same coordinate frame. In other words, k in (1) corresponds to Z in frame XYZ, and j in (2) corresponds to y1 in x1y1z1. And these are 2 different, distinguish frames, so I think the second assumption used by the author is incorrect.
What do you think about this? Any answer would be appreciated. Thank you.
author uses 2 assumptions about the standard basis vectors i, j, k...
it is not assumption!
You not understand cross product and dot product see
http://en.wikipedia.org/wiki/Cross_product
http://en.wikipedia.org/wiki/Dot_product
3 mutually orthogonal vectors i, j, k
orthogonal vectors.... What is it(definition)?
Dot_product... What is it(definition)?
Can we define orthogonal vectors via Dot_product?
You must learn a basic of Linear algebra and Complex analysis before understand quaternion.

Traversing a 2D array in an angle

Generally we traverse the array by row or column but here I want to traverse it in an angle.
I will try and explain what I mean,
So lets say if the angle is 45 degree then rather than row by col it would search as (0,0) then (0,1) (1,0) then (0,2) , (1,1) ,(2,0) and so on.. .(sorry could not upload an image as I am new user and not allowed to do so, may be try and imagine/draw an array that would help get what I am trying to say)
But what will happen if the user inputs an angle like 20 degree how can we determine how to search the array.
i just wanted to know if there is any algorithm which does something similar to this? Programming language is not an issue i guess the issue is more of algoritham sort.
Any ideas would be welcome.
Please feel free to ask if I am not able to explain clearly what I am looking for.
Thanks guys.
Easy. Take an angle (let's say 45). This corresponds to a vector v=(1, 1) in your case. (This can be normalized to a unitary vector (sqrt(2)/2, sqrt(2)/2), but this is not necessary)
For every single point in your array, you have their coordinates (x, y). Simply do the scalar product of these coordinates with the vector. Let's call f(x, y) = scalarProduct((x, y), v)
Sort the values of f(x, y) and you've got the "traversing" you're looking for!
A real example.
Your matrix is 3x3
The scalar products are :
(0,0).(1,1) = 0
(0,1).(1,1) = 1
(0,2).(1,1) = 2
(1,0).(1,1) = 1
(1,1).(1,1) = 2
(1,2).(1,1) = 3
(2,0).(1,1) = 2
(2,1).(1,1) = 3
(2,2).(1,1) = 4
If you order these scalar products by ascending order, you obtain the ordering (0,0), (1,0), (1,0), (2,0), (1,1), (0,2), (2,1)...
And if you want to do it with the angle 20, replace all occurences of v=(1, 1) with v=(cos(20), sin(20))
Here's an illustration of a geometrical interpretation. The scalar products correspond to the intersections of the vector v (in red) with the blue lines.
For every starting point (the leftmost point of every row), use trigonometry to determine an ending point for the given angle. The tan(angle) is defined as (height difference / width of the array), so your height differece is tan(angle)*(witdh of the array). You only have to calculate the height difference once. If y+height difference is greater than the height of the array, just subtract the height (or use the modulo operator).
Now that you have a starting point and an ending point you could use Bresenham's Algorithm to determine the points in between: http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
You want to look for a space-filling-curve for example a morton curve or z-curve. If you want to subdivide the array in 4 tiles you may want to look for a hilbert curve or a moore curve.

support vector machines - a simple explanation?

So, i'm trying to understand how the SVM algorithm works but i just cannot figure out how you transform some datasets in points of n-dimensional plane that would have a mathematical meaning in order to separate the points through a hyperplane and clasify them.
There's an example here, they are trying to clasify pictures of tigers and elephants, they say "We digitize them into 100x100 pixel images, so we have x in n-dimensional plane, where n=10,000", but my question is how do they transform the matrices that actually represent just some color codes IN points that have a methematical meaning in order to clasify them in 2 categories?
Probably someone can explain me this in a 2D example because any graphical representation i see it's just 2D, not nD.
The short answer is: they don't transform the matrices, but treat each element in the matrix as a dimension (in machine learning each element would be called a Feature).
Thus, they need classify elements with 100x100 = 10000 features each. In the linear SVM case, they do so using a hyperplane, which divides the 10,000-dimensional space into two distinct regions.
A longer answer would be:
Consider your 2D case. Now, you want to separate a set of two-dimensional elements. This means that each element in your set can be described mathematically as a 2-tuple, namely: e = (x1, x2). For example, in your figure, some full dots might be: {(1,3), (2,4)}, and some hollow ones might be {(4,2), (5,1)}. Note that in order to classify them with a linear classifier, you need a 2-dimensional linear classifier, which would yield a decision rule which might look like this:
e = (x1, x2)
if (w1 * x1 + w2 * x2) > C : decide that e is a full dot.
otherwise : e is hollow.
Note that the classifier is linear, as it is a linear combination of the elements of e. The 'w's are called 'weights', and 'C' is the decision threshold. a linear function with 2-elements as above is simply a line, that's why in your figures the H's are lines.
Now, back to our n-dimensional case, you can probably figure our that a line will not do the trick. In the 3D case, we would need a plane: (w1 * x1 + w2 * x2 + w2 * x3) > C, and in the n-dimensional case, we would need a hyperplane: (w1 * x1 + w2 * x2 + ... + wn * xn) > C, which is damn hard to imagine, none the less to draw :-).

calculating the potential effect of inaccurate triangle vertex positions on the triangle edge lenghts

i'm not sure how to solve the following problem:
i have a triangle with each of the three known vertex positions A,B,C being inaccurate, meaning they can each deviate up to certain known radii rA, rB, rC into arbitrary directions.
given such a triangle, i want to calculate how much the difference of two specific edge lengths (for instance the difference between lengths of edge a and edge b) of the triangle may change in the worst case. is there any elegant mathematical solution to this problem?
the naive way i thought of is calculating all 360^3 angle combinations and measuring the edge differences for each case, which is a rather high overhead.
The following image illustrates the solution:
MinMaxEdgeDiff.png http://www.freeimagehosting.net/uploads/b0f0f84635.png
Some points to note:
Line segments AC1 and BC1 represent the largest possible value of |BC| - |AC|, while lines AC2 and BC2 represent the smallest possible value. At C1, the tangent to the circle must bisect the angle made by AC1 and BC1; likewise for C2.
AC1 (when extended via the dashed line) and AC2 both go through A. Likewise, BC1 and BC2 go through B. Any deviation from the center, and the lines would longer be maximally long or minimally short.
The largest and smallest differences are:
d1 = |BC1| - |AC1| = (|B->C1| + _rB_) - (|A->C1| - _rA_)
= |B->C1| - |A->C1| + (_rA_ + _rB_)
d2 = |BC2| - |AC2| = (|B->C2| - _rB_) - (|A->C2| + _rA_)
= |B->C2| - |A->C2| - (_rA_ + _rB_)
Thus the variation between the largest and smallest differences is:
d1 - d2 = (|B->C1| - |A->C1|) - (|B->C2| - |A->C2|) + 2*(_rA_ + _rB_)
The last point hints that the solution can be found by solving from the centers A and B, and then adding the radii rA and rB. Thus the locations of C1 and C2 may be discovered iteratively (and separately, since they are independent of each other) by varying just a single angle around C's bounding circle.
I suspect that there's an analytical solution. It's an interesting problem, but not enough for me to bash my head against this particular task. Sorry. ;-)

Resources