Finding Definitess of a Matrix

17 views (last 30 days)
FelixAdam Fournier
FelixAdam Fournier on 4 Feb 2022
Answered: Matt J on 4 Feb 2022
Hello guys. I'm quit beginner. I'm trying to ask a user to input a matrix. But the goal is I need to be able to find the definitess of the matrix that will be input. I want the option that my code will say it's positive definite, positive semi-definite,indefinite, negative definite or negative semi-definite. Could you guys tell me or show me what is missing or function I should use so I can have the other option as well.
m=input('Enter the number of row (under 5): ');
n=input('Enter the number of column (under 5): ');
if m == n
disp('Good Size')
elseif m >= 5
disp("to large square matrix");
elseif n >= 5
disp("To large square matrix");
end
for i=1:m
for j=1:n
a(i,j)=input('enter the elements (each Number in row order): ');
end
end
a = reshape(a,m,n)
try chol(a)
disp("Matrix is symmetric positive definite")
catch ME
disp('Matrix is not symmetric positive definite')
end
tf = issymmetric(a)
d = eig(a)
isposdef = all(d > tol)
issemidef = all(d > -tol)

Answers (1)

Matt J
Matt J on 4 Feb 2022
You alread have code that checks if a is postive (semi) definite. You can use that to see if -a is positive (semi) definite, which would imply that a is negative (semi) definite. If none of the above, you can conclude that it is indefinite.

Categories

Find more on Linear Algebra in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!