Vous êtes sur la page 1sur 2

MATLAB Source Code

% Ask user to enter input matrix


a=input('Please enter matrix:');
display(a)
% Find dimensions of input matrix
[m,n] = size(a);
% m is number of row,n is number of column
% If input matrix is not square, stop function
if m ~= n
% if number of row is not equal to the number of column
disp('This is not a Square Matrix')
end
% If input matrix is square,use forward elimination
if m == n
% if number of row equal to the number of column
for j = 1:n-1
% j is column of matrix
for i = j+1:n
% i is row of matrix
f= a(i,j)/a(j,j);
% f is factor
a(i,j:n)=a(i,j:n)-f*a(j,j:n);
% find new value for each
row except first row
end
end
det=1;
% set the value of determinant equal to 1
for j=1:n
det=det*a(j,j); % multiply the value diagonally to get determinant
end
display(det)
end

Title: Write a programme that receives input from user and calculates the determinant of the
input.

MATLAB
Flow chart
Start

Input Matrix, a

If square matrix
m=n
m=no. of row
n= no. of column

TRUE

Set det=1
det= determinant
for j=1:n

Value of determinant
det=det*a(j,j)

FALSE

Output
No Determinant of Matrix a

for j = 1:n-1
j = column of matrix

for i = j+1:n
i = row of matrix

f= a(i,j)/a(j,j)
f = factor
To get new matrix a
a(i,j:n)=a(i,j:n)-f*a(j,j:n)
Output
Determinant of Matrix a

End

Vous aimerez peut-être aussi