From 309c5d8f7ff8c36235222d079955cd3783bb7ad0 Mon Sep 17 00:00:00 2001 From: wukong Date: Mon, 18 Dec 2023 12:37:31 -0800 Subject: Added a partially working function performing LU decomposition on a square matrix, ludcmp.awk. This is providing correct answers on _some_ test data, further testing debugging required here. --- det.awk | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 det.awk (limited to 'det.awk') diff --git a/det.awk b/det.awk new file mode 100644 index 0000000..b3e5c1f --- /dev/null +++ b/det.awk @@ -0,0 +1,57 @@ +#!/usr/bin/awk -f + +### det.awk +# determinant via LU +# input: square array as delimited text +# output: (scalar) determinant + +BEGIN { + OFS = "\t" + sign = "[+-]?" + decimal = "[0-9]+[.]?[0-9]*" + fraction = "[.][0-9]*" + exponent = "([Ee]" sign "[0-9]+)?" + number = "^" sign "(" decimal "|" fraction ")" exponent "$" +} + +NR == 1 { + for (y=1; y<=NF; y++) + ($y ~ number) ? header[y] = "col" y : header[y] = $y +} + +NF > 0 { + (NF > nf_max) ? nf_max = NF : nf_max = nf_max + + ### columns + for (y=1; y<=nf_max; y++) { + ### rows + if ($y !~ number) { + continue + } + else { + read_data[NR,y] = $y + col_sum[y] += $y + row_sum[NR] += $y + } + } +} + +END { + print length(row_sum), length(col_sum) + ### columns + for (y=1; y<=nf_max; y++) { + if (y in col_sum) { + ### rows + for (x=1; x<=NR; x++) { + if (x in row_sum) { + printf("[" OFMT "," OFMT "]" OFS OFMT OFS OFMT, + x, y, read_data[x,y], col_sum[y]) + if (x < nf_max) + printf(OFS) + } + } + } + printf(ORS) + } +} + -- cgit v1.2.3