+ 1
MATLAP help
Who can help me on some code i wrote but i have error in MATLAP ( easy code ) The code A=input('type your 3*3 matrix'); disp(A) answer=input('if the matrix is 3by3 type Y, otherwise type N'); while answer=='N' A=input('type your 3*3 matrix again'); answer=input('if the matrix is 3by3 type Y, otherwise type N'); end if det(A)==0; disp('your matrix is singular') else disp(inv(A)) end
1 Answer
0
Hey bro, your code is close to fine but requires some attention,
First remove semicolon in IF statement to avoid warning...
Now thw second thing is that,,,
when you are checking for determinant i.e. if det(A) == 0
you should keep in mind that det(A) may not be exactly zero , result may be very close to zero but not exact 0, that's why matlab will give a warning
`Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.067522e-18.`
for ex.- det(A) is 1.6653e-16, which is almost zero but MATLAB will not assume this approximation that's why det(A) == 0 will return false
So to avoid this issue, use condition like
if (det(A) - 0) < 0.00001
So this line will give expected results....
Final changed code is pasted below....
A=input('type your 3*3 matrix: ');
disp(A)
answer=input('if the matrix is 3by3 type Y, otherwise type N: ');
while answer=='N'
A=input('type your 3*3 matrix again: ');
answer=input('if the matrix is 3by3 type Y, otherwise type N: ');
end
if (det(A)-0) < 0.00001
disp('your matrix is singular')
else
disp(inv(A))
end
Thanks for asking....