矩阵求逆网上也有很多java及C程序,由于帮朋友写一小程序其中要用到矩阵求逆,本打算通过ORACLE直接调用外部C++程序实现,但想想不如直接用pl/sql实现,
TYPE ONE_array_type IS TABLE OF NUMBER
INDEX BY BINARY_INTEGER;
--二维数组定义
TYPE two_array_type IS TABLE OF ONE_array_type
INDEX BY BINARY_INTEGER;
INDEX BY BINARY_INTEGER;
--二维数组定义
TYPE two_array_type IS TABLE OF ONE_array_type
INDEX BY BINARY_INTEGER;
---方正求逆
procedure P_Matrix_QN(IO_array in out two_array_type) is
v_bs1 number;
v_bs number;
v_idx number;
BEGIN
v_idx := IO_array.count;
for k in 1 .. v_idx loop
for t in v_idx + 1 .. 2 * v_idx loop
if t - k = v_idx then
IO_array(k)(t) := 1;
else
IO_array(k)(t) := 0;
end if;
end loop;
end loop;
--开始转换
for k in 1 .. v_idx loop
if IO_array(k) (k) != 1 then
v_bs := IO_array(k) (k);
IO_array(k)(k) := 1;
for t in k + 1 .. 2 * v_idx loop
IO_array(k)(t) := IO_array(k) (t) / v_bs;
end loop;
end if;
for q in 1 .. v_idx loop
if q != k then
v_bs1 := IO_array(q) (k);
for p in 1 .. v_idx * 2 loop
--Vp[q][p]-=bs*Vp[k][p];
IO_array(q)(p) := IO_array(q) (p) - v_bs1 * IO_array(k) (p);
end loop;
else
null;
end if;
end loop;
end loop;
--P_PRINT(17,IO_array);
END;
procedure P_Matrix_QN(IO_array in out two_array_type) is
v_bs1 number;
v_bs number;
v_idx number;
BEGIN
v_idx := IO_array.count;
for k in 1 .. v_idx loop
for t in v_idx + 1 .. 2 * v_idx loop
if t - k = v_idx then
IO_array(k)(t) := 1;
else
IO_array(k)(t) := 0;
end if;
end loop;
end loop;
--开始转换
for k in 1 .. v_idx loop
if IO_array(k) (k) != 1 then
v_bs := IO_array(k) (k);
IO_array(k)(k) := 1;
for t in k + 1 .. 2 * v_idx loop
IO_array(k)(t) := IO_array(k) (t) / v_bs;
end loop;
end if;
for q in 1 .. v_idx loop
if q != k then
v_bs1 := IO_array(q) (k);
for p in 1 .. v_idx * 2 loop
--Vp[q][p]-=bs*Vp[k][p];
IO_array(q)(p) := IO_array(q) (p) - v_bs1 * IO_array(k) (p);
end loop;
else
null;
end if;
end loop;
end loop;
--P_PRINT(17,IO_array);
END;
-------------程序很简单,熟悉大学数据中求逆原理应该都会写,但的确在网上没有找到,希望对你有用,,
再者,对于一些矩阵相乘之类的运算,利用ORACLE中表连接+字段运算相当好处理, 而对于一些统计函数,标准差方差ORACLE都有提供很多函数, ORACLE的确很强大。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/134308/viewspace-732335/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/134308/viewspace-732335/