Generate a random orthonormal vector (i) to a given unit vector and (ii) with n-2 predetermined components

15 views (last 30 days)
Hi,
I need to create a random orthonormal vector (i) to a given unit vector and (ii) with (maximal) n-2 predetermined components. For example, say I have the unit vector v1=[-0,52 0,72 -0,19 0,37 -0,18]' (rounded to two digits) and I have the vector v2 with lets say 2 predetermined components that are non-zero, v2=[a b c 0.45 -0.09]. Thus, there should be infinite many solutions for a, b, and c such that v1`*v2=0.
I would like to find an efficient way to generate such a random orthonormal vector v2 where the elements a, b, and c are drawn from a uniform distribution.
I have tried the following:
% start with a random matrix
X = randn(3);
% add some predetermined values
predet=[.4,.5,.4;-.2,-.1,-.2];
V=[X;predet];
% normalize vectors
v1=V(:,1)/norm(V(:,1));
v2=V(:,2)/norm(V(:,2));
% find a random solution for v1'*v2==0 with 3 random entries of v2
check=0;
while check<1
random = -1 + (1-(-1)).*rand(3,1);
v2=[random; v2(4:5)];
% check whether v2 is orthogonal to v1 and v2 has norm 1
if norm(v2)>0.9999 && norm(v2)<1.0001...
&& v1'*v2<=0.0001 && v1'*v2>=-0.0001
check=1;
end
end
However, so far the solution is only a very bad approximation and the algorithm is very slow. Any help on this or suggestions would be very much appreciated.
  1 Comment
Torsten
Torsten on 2 Apr 2020
Just an idea:
Let v1=[v11,v12,...,v1 n], v2=[p1,p2,p3,v24,...,v2n] with unknown p1,p2,p3 satisfying
p1*v11+p2*v12+p3*v13 = -(v14*v24+...+v1n*v2n)
p1^2+p2^2+p3^2=1-(v24^2+...+v2n^2)
Thus the space to sample from is the intersection of the unit sphere and an intersecting planein 3d space.
This intersection is an ellipse.
If you are able to find a parametrization by arclength of this intersection by a parameter, you are done.

Sign in to comment.

Accepted Answer

darova
darova on 27 Mar 2020
What about fsolve
b = 1;
c = 1;
v1 = [-0.52 0.72 -0.19 0.37 -0.18];
v2 = @(x)[x b c 0.45 -0.09];
F = @(x) dot(v1,v2(x));
res = fsolve(F,0.5);
  3 Comments
darova
darova on 2 Apr 2020
Try this
v1 = [-0.52 0.72 -0.19 0.37 -0.18];
v2 = @(x,b,c)[x b c 0.45 -0.09];
F = @(x,b,c) dot(v1,v2(x,b,c));
bb = -10:10;
cc = -10:10;
[B,C] = meshgrid(bb,cc);
A = B*0;
res = 0.5;
opt = optimset('display','off');
for i = 1:size(A,1)
for j = 1:size(A,2)
res = fsolve(F,res,opt, B(i,j),C(i,j));
A(i,j) = res;
end
end
surf(B,C,A)
xlabel('B')
ylabel('C')
zlabel('A')

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!