runtime error: Matrix is singular to working precision. results should be in numbers but coming as NaN

1 view (last 30 days)
i have generated an equation. it is not giving any compiling error. when i run it, it should be giving results in number. instead it is giving results in NaN. please let me know how to solve this problem
this is the code
vy1=vy(1);
disp(vy1);
vy2=vy(2);
disp(vy2);
vy3=vy(3);
disp(vy3);
vy4=vy(4);
disp(vy4);
vy5=vy(5);
disp(vy5);
vy6=vy(6);
disp(vy6);
vy7=vy(7);
disp(vy7);
vy8=vy(8);
disp(vy8);
%assigning values of vy1...vy8 to actual extrinsic and intrinsic parameters
ry21 = vy1;
ry22 = vy2;
ry23 = vy3;
Tyy = vy4;
ary11 = vy5;
ary12 = vy6;
ary13 = vy7;
aTxy = vy8;
%generating the gamma function from the simulated data
gy = sqrt(vy1^2+vy2^2+vy3^2);
disp(gy);
%generating aspect ratio from the simulated data
ay = (sqrt(vy5^2+vy6^2+vy7^2)/gy);
disp(ay);
%generating elements of rotation vector from the simulated data
ry11 = vy5/ay;
ry12 = vy6/ay;
ry13 = vy7/ay;
Txy = vy8/ay;
R1y = [ry11,ry12,ry13];
R2y = [ry21,ry22,ry23];
R3y = cross(R1y,R2y);%generating R3 as R3 is the cross product of R1 amd R2 or R3=R1xR2
disp(R3y);
ry31 = R3y(1);
ry32 = R3y(2);
ry33 = R3y(3);
%generating 1st extrinsic parameter R or the rotation matrix from the
%simulated data
Ry = [R1y;R2y;R3y];
disp(Ry);
%now we need to find another extrinsic parameter T from the simulated data
%x1 = fx*(r11*X1+r12*Y1+r13*Z1+Tx)/(r31*X1+r32*Y1+r33*Z1+Tz);
%x1*Tz + fx*(r11*X1+r12*Y1+r13*Z1+Tx) = -x1(r31*X1+r32*Y1+r33*Z1)
% and
%x2 = fx*(r11*X2+r12*Y2+r13*Z2+Tx)/(r31*X2+r32*Y2+r33*Z2+Tz);
%here x22 = x2
%x2*Tz + fx*(r11*X2+r12*Y2+r13*Z2+Tx) = -x2(r31*X2+r32*Y2+r33*Z2)
%in this case
for h=1:32
A1y = [xhk,(ry11*Xhk+ry12*Yhk+ry13*Zhk+Txy);];
disp(A1y);
end
for h=1:32
B1y = (-xhk*(ry31*Xhk+ry32*Yhk+ry33*Zhk));
disp(B1y);
end
%A1[Tz,fx] = B1;
%[Tz,fx]=(A1t*A1)-1*(A1t.B1)
J = transpose(A1y);
Py = J*A1y;
Qy = J*B1y;
Wy = Py\Qy;
disp(Wy);
break
Tzy = Wy(1);
disp(Tzy);%we can get the 3rd parameter of extrinsic parameter Ty from the simulated data
fxy = Wy(2);%effective focal length at x direction
disp(fxy);
fyy = ay/fxy;%effective focal length at x direction
disp(fyy);
fY = sqrt(fxy^2+fyy^2);%intrinsic parameter f from the simulated data
disp(fY);%here we got the focal length calulated from the simulated data
Ty = [Txy,Tyy,Tzy];%extrinsic parameter T from the simulated data
disp(Ty);
the error is showing at this line
Wy = Py\Qy;
  2 Comments
Sat m
Sat m on 18 Mar 2013
Py=transpose(A1y)*(A1y)
Qy=transpose(A1y)*(B1y)
where A1y and B1y is
for h=1:32
A1y = [xhk,(ry11*Xhk+ry12*Yhk+ry13*Zhk+Txy);];
disp(A1y);
end
for h=1:32
B1y = (-xhk*(ry31*Xhk+ry32*Yhk+ry33*Zhk));
disp(B1y);
end

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 18 Mar 2013
Your code
for h=1:32
A1y = [xhk,(ry11*Xhk+ry12*Yhk+ry13*Zhk+Txy);];
disp(A1y);
end
overwrites A1y completely on each iteration through the loop, but it does so with values that are independent of "h".
If you are trying to use x1k, Y1k and so on, then you cannot do that using that kind of code.
  5 Comments
Walter Roberson
Walter Roberson on 18 Mar 2013
Xh1 = xvals(1:32);
Yh1 = yvals(1:32);
Zh1 = zvals(1:32);
xh1 = fa * Xh1 ./ Zh1; %but what if the z is 0?
yh1 = fa * Yh1 ./ Zh1; %but what if the z is 0?
You did not show how you created xhk

Sign in to comment.

More Answers (0)

Categories

Find more on General Applications 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!