Gaussian elimination only integers?

6 Ansichten (letzte 30 Tage)
Scott Jones
Scott Jones am 20 Feb. 2013
I'm trying to find a way to use matlab to only use integers it do gaussian elimnation. So far I have a code that works but it gives out decimal answers and I can't figure out how to keep them as integers all the way through.
function [ x ] = IntegerGaussrevised( A, b )
%work out the number of equations
N = length(b);
%Gaussian elimination
for column=1:(N-1)
%work on all the rows below the diagonal element
for row = (column+1):N
%work out the value of d
d = A(row,column)/A(column,column);
%do the row operation
A(row,:) = A(row,:)-d*A(column,:);
b(row) = b(row)-d*b(column);
end%loop through rows
end %loop through columns
%back substitution
for row=N:-1:1
x(row) = b(row);
for i=(row+1):N
x(row) = x(row)-A(row,i)*x(i);
end
x(row) = x(row)/A(row,row);
end
%return the answer
x = x;
return
end
Any help would be welcome.

Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by