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

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

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

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

thank you for the link. in the link i saw that they are telling to define it as arrays. so i tried it
A1y = zeros(1,100);
for h=1:32
A1y(h) = [xh1,(ry11*Xh1+ry12*Yh1+ry13*Zh1+Txy)];
disp(A1y);
end
it always shows this error
In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in assignment3 (line 404)
A1y(h) = [xh1,(ry11*Xh1+ry12*Yh1+ry13*Zh1+Txy)];
but when i do this
A1y = zeros(1,100);
for h=1:32
A1y(h) = xh1+ry11*Xh1+ry12*Yh1+Txy;
disp(A1y);
end
it generates the results. can you please tell me how to solve this?
Is A1y intended to be a vector or a 2D matrix? I suspect you want
A1y = zeros(32, 2);
for h = 1 : 32
A1y(h,:) = [xh1,(ry11*Xh1+ry12*Yh1+ry13*Zh1+Txy)];
end
I think even that will not be right, as it will still have the same value for each iteration. I cannot suggest the proper code, though, without seeing how you create the x* and X* and Y* and Z* variables.
here is the entire code about how i created each variable
%3D point generated from the 3D virtual cube
xvals = Pc(:,1);
yvals = Pc(:,2);
zvals = Pc(:,3);
%there are 32 points on 2 surface. so if we wish to run the algorithm with
%this simulated data then we will have 32 rows and 8 columns. so we will get 8 solutions
for h=1:32
Xh1=xvals(h);
disp(Xh1);
end
for h=1:32
Yh1=yvals(h);
disp(Yh1);
end
for h=1:32
Zh1=zvals(h);
disp(Zh1);
end
%2D points generated from the virtual 3D cube
for h=1:32
xh1=fa*Xh1/Zh1;
disp(xh1);
end
for h=1:32
yh1=fa*Yh1/Zh1;
disp(yh1);
end
i generated a graph and from there i evaluated these values. as there are 32 points, so i did not manually assigned them. please let me know how to solve this
i tried to do this assigning with arrays like
X1(h)=xvals(1)
disp(X1(h));
but it is showing error at disp() area
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

Products

Community Treasure Hunt

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

Start Hunting!