matrix inverse in vhdl

Status
Not open for further replies.

ahmedomar_2000

Newbie level 4
Joined
Jul 4, 2013
Messages
6
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Activity points
51
hello
plz , if anyone can help me to write a program that calculates the inverse of a square matrix(4*4) in vhdl
 

Im sure we can help - what problems are you having?
 

i think something like this may do :
type type4x4 is array(integer range 0 to 3, integer range 0 to 3) of natural;
--
function CreateI return type4x4 is
for i in I'range(1) loop
for j in I'range(2) loop
if (i=j) then
I(i,j) = 1;
else
I(i,j) = 0;
end if;
end loop;
end loop;
---------------------------------------------------
-- the inv function.
----------------------------------------------
function Inv(A : type4x4x) return type4x4 is
variable I : type4x4 := CreateI;
pivot : natural;
begin
for in in A'range(1) loop
pivot = A(i,i);
for j in A'range(2) loop
I(i,i) := I(i.j)/pivot; A(i.j) := A(i.j)/pivot;
end loop;

for k in A'range(1) loop
if ((A(k, i) /= 0) and (k /=i)) then
for j in A'range(2) loop
A(k,j) := A(k,j) - A(i,j)*A(k,j);
end loop;
end if;
end loop;
end loop;
return I;
end function;
 
Apart from the several syntax errors, this will work fine in simulation, but will give terrible results for a synthesised circuit.
 

Apart from the several syntax errors, this will work fine in simulation, but will give terrible results for a synthesised circuit.

i just wrote it down in an abstract way , so i was'nt paying attention for syntax errors. also the guy said he wants a "program" so i wrote it like a program.
but turn this into synthesised circuit is not such a big deal - add a clock, some timing signals, and it will get a lot better.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…