| 1 |
% The lualinalg package. |
| 2 |
% Authors: Chetan Shirore and Ajit Kumar |
| 3 |
% Version 1.9. |
| 4 |
% Licensed under LaTeX Project Public License v1.3c or later. The complete license text is available at http://www.latex-project.org/lppl.txt. |
| 5 |
|
| 6 |
\ProvidesPackage{lualinalg}[1.9] |
| 7 |
\RequirePackage{xkeyval} |
| 8 |
\RequirePackage{amsmath} |
| 9 |
\RequirePackage{luamaths} |
| 10 |
\RequirePackage{luacode} |
| 11 |
\begin{luacode*} |
| 12 |
|
| 13 |
-- matrices part |
| 14 |
matrices = {} -- global registry to store matrices. |
| 15 |
|
| 16 |
matrix = {} --module |
| 17 |
|
| 18 |
local matrix_meta = {} |
| 19 |
-- Adding functions to the matrix module. |
| 20 |
function matrix.new(matrix, rows, columns, str) |
| 21 |
if type(rows) == "table" then |
| 22 |
for i = 1, #rows do |
| 23 |
if #rows[1] ~= #rows[i] then |
| 24 |
error("Check input matrix.") |
| 25 |
end |
| 26 |
end |
| 27 |
return setmetatable(rows, matrix_meta) |
| 28 |
end |
| 29 |
local mtx = {} |
| 30 |
if columns == "I" then |
| 31 |
for i = 1, rows do |
| 32 |
mtx[i] = {} |
| 33 |
for j = 1, rows do |
| 34 |
if i == j then |
| 35 |
mtx[i][j] = 1 |
| 36 |
else |
| 37 |
mtx[i][j] = 0 |
| 38 |
end |
| 39 |
end |
| 40 |
end |
| 41 |
return setmetatable(mtx, matrix_meta) |
| 42 |
end |
| 43 |
if str == "zero" then |
| 44 |
for i = 1, rows do |
| 45 |
mtx[i] = {} |
| 46 |
for j = 1, columns do |
| 47 |
mtx[i][j] = 0 |
| 48 |
end |
| 49 |
end |
| 50 |
return setmetatable(mtx, matrix_meta) |
| 51 |
end |
| 52 |
end |
| 53 |
|
| 54 |
setmetatable( |
| 55 |
matrix, |
| 56 |
{__call = function(...) |
| 57 |
return matrix.new(...) |
| 58 |
end} |
| 59 |
) |
| 60 |
|
| 61 |
function matrix.add(m1, m2) |
| 62 |
local mtx = {} |
| 63 |
for i = 1, #m1 do |
| 64 |
local m3i = {} |
| 65 |
mtx[i] = m3i |
| 66 |
for j = 1, #m1[1] do |
| 67 |
m3i[j] = m1[i][j] + m2[i][j] |
| 68 |
end |
| 69 |
end |
| 70 |
return setmetatable(mtx, matrix_meta) |
| 71 |
end |
| 72 |
|
| 73 |
function matrix.sub(m1, m2) |
| 74 |
local mtx = {} |
| 75 |
for i = 1, #m1 do |
| 76 |
local m3i = {} |
| 77 |
mtx[i] = m3i |
| 78 |
for j = 1, #m1[1] do |
| 79 |
m3i[j] = m1[i][j] - m2[i][j] |
| 80 |
end |
| 81 |
end |
| 82 |
return setmetatable(mtx, matrix_meta) |
| 83 |
end |
| 84 |
|
| 85 |
function matrix.mulnum(m1, num) |
| 86 |
local mtx = {} |
| 87 |
-- multiply elements with number |
| 88 |
for i = 1, #m1 do |
| 89 |
mtx[i] = {} |
| 90 |
for j = 1, #m1[1] do |
| 91 |
mtx[i][j] = m1[i][j] * num |
| 92 |
end |
| 93 |
end |
| 94 |
return setmetatable(mtx, matrix_meta) |
| 95 |
end |
| 96 |
|
| 97 |
function matrix.mul(m1, m2) |
| 98 |
local mtx = {} |
| 99 |
for i = 1, #m1 do |
| 100 |
mtx[i] = {} |
| 101 |
for j = 1, #m2[1] do |
| 102 |
local num = m1[i][1] * m2[1][j] |
| 103 |
for n = 2, #m1[1] do |
| 104 |
num = num + m1[i][n] * m2[n][j] |
| 105 |
end |
| 106 |
mtx[i][j] = num |
| 107 |
end |
| 108 |
end |
| 109 |
return setmetatable(mtx, matrix_meta) |
| 110 |
end |
| 111 |
|
| 112 |
function matrix.swapRows(m1, p, q) |
| 113 |
local mtx = {} |
| 114 |
for i = 1, #m1 do |
| 115 |
mtx[i] = {} |
| 116 |
for j = 1, #m1[1] do |
| 117 |
mtx[i][j] = m1[i][j] |
| 118 |
end |
| 119 |
end |
| 120 |
for j = 1, #m1[1] do |
| 121 |
rowHold = m1[p][j] |
| 122 |
mtx[p][j] = m1[q][j] |
| 123 |
mtx[q][j] = rowHold |
| 124 |
end |
| 125 |
return setmetatable(mtx, matrix_meta) |
| 126 |
end |
| 127 |
|
| 128 |
function matrix.swapCols(m1, p, q) |
| 129 |
local mtx = {} |
| 130 |
for i = 1, #m1 do |
| 131 |
mtx[i] = {} |
| 132 |
for j = 1, #m1[1] do |
| 133 |
mtx[i][j] = m1[i][j] |
| 134 |
end |
| 135 |
end |
| 136 |
for j = 1, #m1 do |
| 137 |
rowHold = m1[j][p] |
| 138 |
mtx[j][p] = m1[j][q] |
| 139 |
mtx[j][q] = rowHold |
| 140 |
end |
| 141 |
return setmetatable(mtx, matrix_meta) |
| 142 |
end |
| 143 |
|
| 144 |
function matrix.mulRow(m1, p, k) |
| 145 |
local mtx = {} |
| 146 |
for i = 1, #m1 do |
| 147 |
mtx[i] = {} |
| 148 |
for j = 1, #m1[1] do |
| 149 |
mtx[i][j] = m1[i][j] |
| 150 |
end |
| 151 |
end |
| 152 |
for j = 1, #m1[1] do |
| 153 |
mtx[p][j] = k * m1[p][j] |
| 154 |
end |
| 155 |
return setmetatable(mtx, matrix_meta) |
| 156 |
end |
| 157 |
|
| 158 |
function matrix.mulAddRow(m1, k, p, q) |
| 159 |
if p == q then |
| 160 |
error("Can't operate on same row.") |
| 161 |
end |
| 162 |
local mtx = {} |
| 163 |
for i = 1, #m1 do |
| 164 |
mtx[i] = {} |
| 165 |
for j = 1, #m1[1] do |
| 166 |
mtx[i][j] = m1[i][j] |
| 167 |
end |
| 168 |
end |
| 169 |
for j = 1, #m1[1] do |
| 170 |
mtx[q][j] = k * (mtx[p][j]) + mtx[q][j] |
| 171 |
end |
| 172 |
return setmetatable(mtx, matrix_meta) |
| 173 |
end |
| 174 |
|
| 175 |
function matrix.mulCol(m1, p, k) |
| 176 |
local mtx = {} |
| 177 |
for i = 1, #m1 do |
| 178 |
mtx[i] = {} |
| 179 |
for j = 1, #m1[1] do |
| 180 |
mtx[i][j] = m1[i][j] |
| 181 |
end |
| 182 |
end |
| 183 |
for j = 1, #m1 do |
| 184 |
mtx[j][p] = k * m1[j][p] |
| 185 |
end |
| 186 |
return setmetatable(mtx, matrix_meta) |
| 187 |
end |
| 188 |
|
| 189 |
function matrix.mulAddCol(m1, k, p, q) |
| 190 |
if p == q then |
| 191 |
error("Can't operate on same column.") |
| 192 |
end |
| 193 |
local mtx = {} |
| 194 |
for i = 1, #m1 do |
| 195 |
mtx[i] = {} |
| 196 |
for j = 1, #m1[1] do |
| 197 |
mtx[i][j] = m1[i][j] |
| 198 |
end |
| 199 |
end |
| 200 |
for j = 1, #m1 do |
| 201 |
mtx[j][q] = k * mtx[j][p] + mtx[j][q] |
| 202 |
end |
| 203 |
return setmetatable(mtx, matrix_meta) |
| 204 |
end |
| 205 |
|
| 206 |
function matrix.transpose(m1) |
| 207 |
local mtx = {} |
| 208 |
for i = 1, #m1[1] do |
| 209 |
mtx[i] = {} |
| 210 |
for j = 1, #m1 do |
| 211 |
mtx[i][j] = m1[j][i] |
| 212 |
end |
| 213 |
end |
| 214 |
return setmetatable(mtx, matrix_meta) |
| 215 |
end |
| 216 |
|
| 217 |
function matrix.subm(m1, i1, j1, i2, j2) |
| 218 |
local mtx = {} |
| 219 |
for i = i1, i2 do |
| 220 |
local _i = i - i1 + 1 |
| 221 |
mtx[_i] = {} |
| 222 |
for j = j1, j2 do |
| 223 |
local _j = j - j1 + 1 |
| 224 |
mtx[_i][_j] = m1[i][j] |
| 225 |
end |
| 226 |
end |
| 227 |
return setmetatable(mtx, matrix_meta) |
| 228 |
end |
| 229 |
|
| 230 |
function matrix.concath(m1, m2) |
| 231 |
if #m1 ~= #m2 then |
| 232 |
error("No. of rows must be equal.") |
| 233 |
end |
| 234 |
local mtx = {} |
| 235 |
local offset = #m1[1] |
| 236 |
for i = 1, #m1 do |
| 237 |
mtx[i] = {} |
| 238 |
for j = 1, offset do |
| 239 |
mtx[i][j] = m1[i][j] |
| 240 |
end |
| 241 |
for j = 1, #m2[1] do |
| 242 |
mtx[i][j + offset] = m2[i][j] |
| 243 |
end |
| 244 |
end |
| 245 |
return setmetatable(mtx, matrix_meta) |
| 246 |
end |
| 247 |
|
| 248 |
function matrix.concatv(m1, m2) |
| 249 |
if #m1[1] ~= #m2[1] then |
| 250 |
error("No. of columns must be equal.") |
| 251 |
end |
| 252 |
local mtx = {} |
| 253 |
for i = 1, #m1 do |
| 254 |
mtx[i] = {} |
| 255 |
for j = 1, #m1[1] do |
| 256 |
mtx[i][j] = m1[i][j] |
| 257 |
end |
| 258 |
end |
| 259 |
local offset = #mtx |
| 260 |
for i = 1, #m2 do |
| 261 |
local _i = i + offset |
| 262 |
mtx[_i] = {} |
| 263 |
for j = 1, #m2[1] do |
| 264 |
mtx[_i][j] = m2[i][j] |
| 265 |
end |
| 266 |
end |
| 267 |
return setmetatable(mtx, matrix_meta) |
| 268 |
end |
| 269 |
|
| 270 |
function matrix.rows(mtx) |
| 271 |
return #mtx |
| 272 |
end |
| 273 |
|
| 274 |
function matrix.columns(mtx) |
| 275 |
return #mtx[1] |
| 276 |
end |
| 277 |
|
| 278 |
setmetatable( |
| 279 |
matrix, |
| 280 |
{__call = function(...) |
| 281 |
return matrix.new(...) |
| 282 |
end} |
| 283 |
) |
| 284 |
|
| 285 |
function matrix.getelement(mtx, i, j) |
| 286 |
if mtx[i] and mtx[i][j] then |
| 287 |
return mtx[i][j] |
| 288 |
end |
| 289 |
end |
| 290 |
|
| 291 |
function matrix.setelement(mtx, i, j, value) |
| 292 |
if matrix.getelement(mtx, i, j) then |
| 293 |
mtx[i][j] = value |
| 294 |
return value |
| 295 |
end |
| 296 |
end |
| 297 |
|
| 298 |
function matrix.invert(m1) |
| 299 |
if #m1 ~= #m1[1] then |
| 300 |
error("matrix not square") |
| 301 |
end |
| 302 |
if matrix.det(m1) == 0 then |
| 303 |
error("matrix not invertible") |
| 304 |
end |
| 305 |
local mtx = {} |
| 306 |
local idnt = matrix(#m1, "I") |
| 307 |
mtx = matrix.subm(matrix.rref(matrix.concath(m1, idnt)), 1, #m1 + 1, #m1, #m1 + #m1) |
| 308 |
return mtx |
| 309 |
end |
| 310 |
|
| 311 |
function matrix.trace(m1) |
| 312 |
if #m1 ~= #m1[1] then |
| 313 |
error("matrix not square") |
| 314 |
end |
| 315 |
local sum = 0 |
| 316 |
|
| 317 |
for i = 1, #m1 do |
| 318 |
for j = 1, #m1[1] do |
| 319 |
if i == j then |
| 320 |
sum = sum + m1[i][j] |
| 321 |
end |
| 322 |
end |
| 323 |
end |
| 324 |
|
| 325 |
return sum |
| 326 |
end |
| 327 |
|
| 328 |
function matrix.normF(mtx) |
| 329 |
local result = 0 |
| 330 |
for i = 1, #mtx do |
| 331 |
for j = 1, #mtx[1] do |
| 332 |
local e = mtx[i][j] |
| 333 |
result = result + complex.abs(complex(e)) ^ 2 |
| 334 |
end |
| 335 |
end |
| 336 |
return complex.sqrt(complex(result)) |
| 337 |
end |
| 338 |
|
| 339 |
function matrix.normmax(mtx) |
| 340 |
local result = 0 |
| 341 |
for i = 1, #mtx do |
| 342 |
for j = 1, #mtx[1] do |
| 343 |
local e = complex.abs(complex(mtx[i][j])) |
| 344 |
if e > result then |
| 345 |
result = e |
| 346 |
end |
| 347 |
end |
| 348 |
end |
| 349 |
return result |
| 350 |
end |
| 351 |
|
| 352 |
function matrix.norminfty(mtx) |
| 353 |
local e = 0 |
| 354 |
local result = 0 |
| 355 |
for i = 1, #mtx do |
| 356 |
local e = 0 |
| 357 |
for j = 1, #mtx[1] do |
| 358 |
e = e + complex.abs(complex(mtx[i][j])) |
| 359 |
end |
| 360 |
if e > result then |
| 361 |
result = e |
| 362 |
end |
| 363 |
end |
| 364 |
return result |
| 365 |
end |
| 366 |
|
| 367 |
function matrix.norm1(mtx) |
| 368 |
local e = 0 |
| 369 |
local result = 0 |
| 370 |
for i = 1, #mtx[1] do |
| 371 |
local e = 0 |
| 372 |
for j = 1, #mtx do |
| 373 |
e = e + complex.abs(complex(mtx[j][i])) |
| 374 |
end |
| 375 |
if e > result then |
| 376 |
result = e |
| 377 |
end |
| 378 |
end |
| 379 |
return result |
| 380 |
end |
| 381 |
|
| 382 |
function matrix.conjugate(m1) |
| 383 |
local mtx = matrix.copy(m1) |
| 384 |
for i = 1, #mtx do |
| 385 |
for j = 1, #mtx[1] do |
| 386 |
mtx[i][j] = complex.conjugate(complex(mtx[i][j])) |
| 387 |
end |
| 388 |
end |
| 389 |
return setmetatable(mtx, matrix_meta) |
| 390 |
end |
| 391 |
|
| 392 |
function matrix.conjugateT(m1) |
| 393 |
local mtx = {} |
| 394 |
for i = 1, #m1[1] do |
| 395 |
mtx[i] = {} |
| 396 |
for j = 1, #m1 do |
| 397 |
mtx[i][j] = complex.conjugate(complex(m1[j][i])) |
| 398 |
end |
| 399 |
end |
| 400 |
return setmetatable(mtx, matrix_meta) |
| 401 |
end |
| 402 |
|
| 403 |
function copy(x) |
| 404 |
return type(x) == "table" and x.copy(x) or x |
| 405 |
end |
| 406 |
|
| 407 |
function matrix.pow(m1, num) |
| 408 |
assert(num == math.floor(num), "exponent not an integer") |
| 409 |
if num == 0 then |
| 410 |
return matrix:new(#m1, "I") |
| 411 |
end |
| 412 |
if num < 0 then |
| 413 |
local rank |
| 414 |
m1, rank = matrix.invert(m1) |
| 415 |
if not m1 then |
| 416 |
return m1, rank |
| 417 |
end -- singular |
| 418 |
num = -num |
| 419 |
end |
| 420 |
local mtx = matrix.copy(m1) |
| 421 |
for i = 2, num do |
| 422 |
mtx = matrix.mul(mtx, m1) |
| 423 |
end |
| 424 |
return mtx |
| 425 |
end |
| 426 |
|
| 427 |
function matrix.createrandom(nrow, ncol, start, stop) |
| 428 |
mtx = {} |
| 429 |
for i = 1, nrow do |
| 430 |
mtx[i] = {} |
| 431 |
for j = 1, ncol do |
| 432 |
mtx[i][j] = math.random(start, stop) |
| 433 |
mtx[i][j] = mtx[i][j] + math.min(math.random(), math.abs(mtx[i][j] - start), math.abs(stop - mtx[i][j])) |
| 434 |
end |
| 435 |
end |
| 436 |
return setmetatable(mtx, matrix_meta) |
| 437 |
end |
| 438 |
|
| 439 |
function matrix.process(m1) |
| 440 |
--m1=load("return "..m1)() |
| 441 |
return matrix.mulnum(m1, 1) |
| 442 |
end |
| 443 |
|
| 444 |
function matrix.det(m1) |
| 445 |
assert(#m1 == #m1[1], "matrix not square") |
| 446 |
|
| 447 |
local size = #m1 |
| 448 |
|
| 449 |
if size == 1 then |
| 450 |
return m1[1][1] |
| 451 |
end |
| 452 |
|
| 453 |
if size == 2 then |
| 454 |
return m1[1][1] * m1[2][2] - m1[2][1] * m1[1][2] |
| 455 |
end |
| 456 |
|
| 457 |
if size == 3 then |
| 458 |
return (m1[1][1] * m1[2][2] * m1[3][3] + m1[1][2] * m1[2][3] * m1[3][1] + m1[1][3] * m1[2][1] * m1[3][2] - |
| 459 |
m1[1][3] * m1[2][2] * m1[3][1] - |
| 460 |
m1[1][1] * m1[2][3] * m1[3][2] - |
| 461 |
m1[1][2] * m1[2][1] * m1[3][3]) |
| 462 |
end |
| 463 |
|
| 464 |
local e = m1[1][1] |
| 465 |
local zero = type(e) == "table" and e.zero or 0 |
| 466 |
local norm2 = type(e) == "table" and e.norm2 or number_norm2 |
| 467 |
|
| 468 |
local mtx = matrix.copy(m1) |
| 469 |
local det = 1 |
| 470 |
|
| 471 |
for j = 1, #mtx[1] do |
| 472 |
local rows = #mtx |
| 473 |
local subdet, xrow |
| 474 |
for i = 1, rows do |
| 475 |
local e = mtx[i][j] |
| 476 |
if not subdet then |
| 477 |
if e ~= zero then |
| 478 |
subdet, xrow = e, i |
| 479 |
end |
| 480 |
elseif e ~= zero and math.abs(norm2(e) - 1) < math.abs(norm2(subdet) - 1) then |
| 481 |
subdet, xrow = e, i |
| 482 |
end |
| 483 |
end |
| 484 |
if subdet then |
| 485 |
if xrow ~= rows then |
| 486 |
mtx[rows], mtx[xrow] = mtx[xrow], mtx[rows] |
| 487 |
det = -det |
| 488 |
end |
| 489 |
|
| 490 |
for i = 1, rows - 1 do |
| 491 |
if mtx[i][j] ~= zero then |
| 492 |
local factor = mtx[i][j] / subdet |
| 493 |
for n = j + 1, #mtx[1] do |
| 494 |
mtx[i][n] = mtx[i][n] - factor * mtx[rows][n] |
| 495 |
end |
| 496 |
end |
| 497 |
end |
| 498 |
if math.fmod(rows, 2) == 0 then |
| 499 |
det = -det |
| 500 |
end |
| 501 |
det = det * subdet |
| 502 |
table.remove(mtx) |
| 503 |
else |
| 504 |
return det * 0 |
| 505 |
end |
| 506 |
end |
| 507 |
|
| 508 |
return det |
| 509 |
end |
| 510 |
|
| 511 |
function matrix.copy(m1) |
| 512 |
local mtx = {} |
| 513 |
for i = 1, #m1 do |
| 514 |
mtx[i] = {} |
| 515 |
for j = 1, #m1[1] do |
| 516 |
mtx[i][j] = m1[i][j] |
| 517 |
end |
| 518 |
end |
| 519 |
return setmetatable(mtx, matrix_meta) |
| 520 |
end |
| 521 |
|
| 522 |
norm2 = type(e) == "table" and e.norm2 or number_norm2 |
| 523 |
|
| 524 |
function number_norm2(x) |
| 525 |
return x * x |
| 526 |
end |
| 527 |
|
| 528 |
function matrix.op(exp) |
| 529 |
return load("return " .. exp, exp, "t", matrices)() |
| 530 |
end |
| 531 |
|
| 532 |
function matrix.rref(mtx) |
| 533 |
local mtx = matrix.copy(mtx) |
| 534 |
step = 1 |
| 535 |
lead = 1 |
| 536 |
rowCount = #mtx |
| 537 |
columnCount = #mtx[1] |
| 538 |
for r = 1, rowCount do |
| 539 |
if lead > columnCount then |
| 540 |
return mtx |
| 541 |
end |
| 542 |
i = r |
| 543 |
while (mtx[i][lead] == 0) do |
| 544 |
i = i + 1 |
| 545 |
if (i - 1 == rowCount) then |
| 546 |
i = r |
| 547 |
if (columnCount == lead) then |
| 548 |
return mtx |
| 549 |
end |
| 550 |
lead = lead + 1 |
| 551 |
end |
| 552 |
end |
| 553 |
|
| 554 |
if i ~= r then |
| 555 |
mtx = matrix.swapRows(mtx, i, r) |
| 556 |
end |
| 557 |
|
| 558 |
local m = mtx[r][lead] |
| 559 |
if (mtx[r][lead] ~= 0) then |
| 560 |
for u = 1, columnCount do |
| 561 |
mtx[r][u] = mtx[r][u] / m |
| 562 |
end |
| 563 |
end |
| 564 |
for i = 1, rowCount do |
| 565 |
local m = mtx[i][lead] |
| 566 |
if (i ~= r) then |
| 567 |
for v = 1, columnCount do |
| 568 |
mtx[i][v] = mtx[i][v] + ((-m) * (mtx[r][v])) |
| 569 |
end |
| 570 |
end |
| 571 |
end |
| 572 |
lead = lead + 1 |
| 573 |
end |
| 574 |
return mtx |
| 575 |
end |
| 576 |
|
| 577 |
function matrix.rref0E(mtx, fom, dignum) |
| 578 |
local strng = "" |
| 579 |
truncate = truncate or 6 |
| 580 |
local mtx = matrix.copy(mtx) |
| 581 |
step = 1 |
| 582 |
lead = 1 |
| 583 |
stepCnt = 0 |
| 584 |
rowCount = #mtx |
| 585 |
columnCount = #mtx[1] |
| 586 |
for r = 1, rowCount do |
| 587 |
if lead > columnCount then |
| 588 |
return mtx |
| 589 |
end |
| 590 |
i = r |
| 591 |
while (mtx[i][lead] == 0) do |
| 592 |
i = i + 1 |
| 593 |
if (i - 1 == rowCount) then |
| 594 |
i = r |
| 595 |
if (columnCount == lead) then |
| 596 |
if stepCnt == 0 then |
| 597 |
stepCnt = stepCnt + 1 |
| 598 |
strng = strng .. "Step " .. tostring(stepCnt) ".$$" .. tostring(matrix.show(mtx, fom, dignum)) |
| 599 |
return strng |
| 600 |
end |
| 601 |
return strng |
| 602 |
end |
| 603 |
lead = lead + 1 |
| 604 |
end |
| 605 |
end |
| 606 |
|
| 607 |
if i ~= r then |
| 608 |
mtx = matrix.swapRows(mtx, i, r) |
| 609 |
stepCnt = stepCnt + 1 |
| 610 |
strng = |
| 611 |
strng .. |
| 612 |
"Step " .. |
| 613 |
tostring(stepCnt) .. |
| 614 |
": Interchange rows " .. |
| 615 |
tostring(i) .. |
| 616 |
" and " .. tostring(r) .. ".$$" .. tostring(matrix.show(mtx, fom, dignum)) .. "$$" |
| 617 |
end |
| 618 |
|
| 619 |
local m = mtx[r][lead] |
| 620 |
if (mtx[r][lead] ~= 0) then |
| 621 |
for u = 1, columnCount do |
| 622 |
mtx[r][u] = mtx[r][u] / m |
| 623 |
end |
| 624 |
if m ~= 1.0 then |
| 625 |
if m ~= complex("1.0") then |
| 626 |
stepCnt = stepCnt + 1 |
| 627 |
strng = |
| 628 |
strng .. |
| 629 |
"Step " .. |
| 630 |
tostring(stepCnt) .. |
| 631 |
": Divide row " .. |
| 632 |
tostring(r) .. |
| 633 |
" by $" .. |
| 634 |
tostring(complex.round(complex(m), dignum)) .. |
| 635 |
"$.$$" .. tostring(matrix.show(mtx, fom, dignum)) .. "$$" |
| 636 |
end |
| 637 |
end |
| 638 |
end |
| 639 |
for i = 1, rowCount do |
| 640 |
local m = mtx[i][lead] |
| 641 |
if (i ~= r) then |
| 642 |
for v = 1, columnCount do |
| 643 |
mtx[i][v] = mtx[i][v] + ((-m) * (mtx[r][v])) |
| 644 |
end |
| 645 |
if m ~= 0 then |
| 646 |
if m ~= complex("0.0") then |
| 647 |
stepCnt = stepCnt + 1 |
| 648 |
strng = |
| 649 |
strng .. |
| 650 |
"Step " .. |
| 651 |
tostring(stepCnt) .. |
| 652 |
": Multiply row " .. |
| 653 |
tostring(r) .. |
| 654 |
" by $" .. |
| 655 |
tostring(complex.round(complex(m), dignum)) .. |
| 656 |
"$ and subtract it from row " .. |
| 657 |
tostring(i) .. |
| 658 |
".$$" .. tostring(matrix.show(mtx, fom, dignum)) .. "$$" |
| 659 |
end |
| 660 |
end |
| 661 |
end |
| 662 |
end |
| 663 |
lead = lead + 1 |
| 664 |
end |
| 665 |
return strng |
| 666 |
end |
| 667 |
|
| 668 |
function matrix.GaussJordan(mtx, augmt) |
| 669 |
local mtx = matrix.copy(mtx) |
| 670 |
local augmt = matrix.copy(augmt) |
| 671 |
step = 1 |
| 672 |
lead = 1 |
| 673 |
rowCount = #mtx |
| 674 |
columnCount = #mtx[1] |
| 675 |
for r = 1, rowCount do |
| 676 |
if lead > columnCount then |
| 677 |
return matrix.concath(mtx, augmt) |
| 678 |
end |
| 679 |
i = r |
| 680 |
while (mtx[i][lead] == 0) do |
| 681 |
i = i + 1 |
| 682 |
if (i - 1 == rowCount) then |
| 683 |
i = r |
| 684 |
if (columnCount == lead) then |
| 685 |
return matrix.concath(mtx, augmt) |
| 686 |
end |
| 687 |
lead = lead + 1 |
| 688 |
end |
| 689 |
end |
| 690 |
|
| 691 |
if i ~= r then |
| 692 |
mtx = matrix.swapRows(mtx, i, r) |
| 693 |
augmt = matrix.swapRows(augmt, i, r) |
| 694 |
end |
| 695 |
|
| 696 |
local m = mtx[r][lead] |
| 697 |
if (mtx[r][lead] ~= 0) then |
| 698 |
for u = 1, columnCount do |
| 699 |
mtx[r][u] = mtx[r][u] / m |
| 700 |
end |
| 701 |
augmt[r][1] = augmt[r][1] / m |
| 702 |
end |
| 703 |
for i = 1, rowCount do |
| 704 |
local m = mtx[i][lead] |
| 705 |
if (i ~= r) then |
| 706 |
for v = 1, columnCount do |
| 707 |
mtx[i][v] = mtx[i][v] - m * mtx[r][v] |
| 708 |
end |
| 709 |
augmt[i][1] = augmt[i][1] - m * augmt[r][1] |
| 710 |
end |
| 711 |
end |
| 712 |
lead = lead + 1 |
| 713 |
end |
| 714 |
return matrix.concath(mtx, augmt) |
| 715 |
end |
| 716 |
|
| 717 |
function matrix.gauss0E(mtx, augmt, fom, dignum) |
| 718 |
local strng = "" |
| 719 |
truncate = truncate or 6 |
| 720 |
local mtx = matrix.copy(mtx) |
| 721 |
local augmt = matrix.copy(augmt) |
| 722 |
if matrix.columns(augmt) ~= 1 then |
| 723 |
error("The second matrix should have only 1 column.") |
| 724 |
end |
| 725 |
step = 1 |
| 726 |
lead = 1 |
| 727 |
stepCnt = 0 |
| 728 |
rowCount = #mtx |
| 729 |
columnCount = #mtx[1] |
| 730 |
for r = 1, rowCount do |
| 731 |
if lead > columnCount then |
| 732 |
return mtx |
| 733 |
end |
| 734 |
i = r |
| 735 |
while (mtx[i][lead] == 0) do |
| 736 |
i = i + 1 |
| 737 |
if (i - 1 == rowCount) then |
| 738 |
i = r |
| 739 |
if (columnCount == lead) then |
| 740 |
if stepCnt == 0 then |
| 741 |
stepCnt = stepCnt + 1 |
| 742 |
strng = |
| 743 |
strng .. |
| 744 |
"Step " .. |
| 745 |
tostring(stepCnt) ".$$" .. |
| 746 |
tostring(matrix.show(matrix.concath(mtx, augmt), fom, dignum)) |
| 747 |
return strng |
| 748 |
end |
| 749 |
return strng |
| 750 |
end |
| 751 |
lead = lead + 1 |
| 752 |
end |
| 753 |
end |
| 754 |
|
| 755 |
if i ~= r then |
| 756 |
mtx = matrix.swapRows(mtx, i, r) |
| 757 |
augmt = matrix.swapRows(augmt, i, r) |
| 758 |
stepCnt = stepCnt + 1 |
| 759 |
strng = |
| 760 |
strng .. |
| 761 |
"Step " .. |
| 762 |
tostring(stepCnt) .. |
| 763 |
": Interchange rows " .. |
| 764 |
tostring(i) .. |
| 765 |
" and " .. tostring(r) .. ".$$" .. tostring(matrix.show(mtx, fom, dignum)) .. "$$" |
| 766 |
end |
| 767 |
|
| 768 |
local m = mtx[r][lead] |
| 769 |
if (mtx[r][lead] ~= 0) then |
| 770 |
for u = 1, columnCount do |
| 771 |
mtx[r][u] = mtx[r][u] / m |
| 772 |
end |
| 773 |
augmt[r][1] = augmt[r][1] / m |
| 774 |
if m ~= 1.0 then |
| 775 |
if m ~= complex("1.0") then |
| 776 |
stepCnt = stepCnt + 1 |
| 777 |
strng = |
| 778 |
strng .. |
| 779 |
"Step " .. |
| 780 |
tostring(stepCnt) .. |
| 781 |
": Divide row " .. |
| 782 |
tostring(r) .. |
| 783 |
" by $" .. |
| 784 |
tostring(complex.round(complex(m), dignum)) .. |
| 785 |
"$. $$" .. |
| 786 |
tostring(matrix.show(matrix.concath(mtx, augmt), fom, dignum)) .. |
| 787 |
"$$" |
| 788 |
end |
| 789 |
end |
| 790 |
end |
| 791 |
for i = 1, rowCount do |
| 792 |
local m = mtx[i][lead] |
| 793 |
if (i ~= r) then |
| 794 |
for v = 1, columnCount do |
| 795 |
mtx[i][v] = mtx[i][v] - m * mtx[r][v] |
| 796 |
end |
| 797 |
augmt[i][1] = augmt[i][1] - m * augmt[r][1] |
| 798 |
if m ~= 0 then |
| 799 |
if m ~= complex("0.0") then |
| 800 |
stepCnt = stepCnt + 1 |
| 801 |
strng = |
| 802 |
strng .. |
| 803 |
"Step " .. |
| 804 |
tostring(stepCnt) .. |
| 805 |
": Multiply row " .. |
| 806 |
tostring(r) .. |
| 807 |
" by $" .. |
| 808 |
tostring(complex.round(complex(m), dignum)) .. |
| 809 |
"$ and subtract it from row " .. |
| 810 |
tostring(i) .. |
| 811 |
".$$" .. |
| 812 |
tostring( |
| 813 |
matrix.show(matrix.concath(mtx, augmt), fom, dignum) |
| 814 |
) .. |
| 815 |
"$$" |
| 816 |
end |
| 817 |
end |
| 818 |
end |
| 819 |
end |
| 820 |
lead = lead + 1 |
| 821 |
end |
| 822 |
return strng |
| 823 |
end |
| 824 |
|
| 825 |
function matrix.rank(m1) |
| 826 |
local mtx = {} |
| 827 |
mtx = matrix.rref(m1) |
| 828 |
rank = #mtx |
| 829 |
for i = 1, #mtx do |
| 830 |
if CheckEqual(mtx[i], 0) then |
| 831 |
rank = rank - 1 |
| 832 |
end |
| 833 |
end |
| 834 |
return rank |
| 835 |
end |
| 836 |
|
| 837 |
function CheckEqual(Values, Number) |
| 838 |
local CheckEqual = true |
| 839 |
local i = 1 |
| 840 |
|
| 841 |
while (CheckEqual and (i <= #Values)) do |
| 842 |
if Values[i] == Number then |
| 843 |
i = i + 1 |
| 844 |
else |
| 845 |
CheckEqual = false |
| 846 |
end |
| 847 |
end |
| 848 |
|
| 849 |
return CheckEqual |
| 850 |
end |
| 851 |
|
| 852 |
function matrix.replace(m1, func, ...) |
| 853 |
local mtx = {} |
| 854 |
for i = 1, #m1 do |
| 855 |
local m1i = m1[i] |
| 856 |
local mtxi = {} |
| 857 |
for j = 1, #m1i do |
| 858 |
mtxi[j] = func(m1i[j], ...) |
| 859 |
end |
| 860 |
mtx[i] = mtxi |
| 861 |
end |
| 862 |
return setmetatable(mtx, matrix_meta) |
| 863 |
end |
| 864 |
|
| 865 |
function matrix.show(mtx, format, dig) |
| 866 |
mtx = matrix.process(mtx) |
| 867 |
local format = format or "bmatrix" |
| 868 |
local dig = dig or 6 |
| 869 |
local str = "\\begin{" .. format .. "}" |
| 870 |
for i = 1, #mtx do |
| 871 |
str = str .. "\t" .. complex.round(complex(mtx[i][1]), dig) |
| 872 |
for j = 2, #mtx[1] do |
| 873 |
str = str .. " & " .. complex.round(complex(mtx[i][j]), dig) |
| 874 |
end |
| 875 |
if i == #mtx then |
| 876 |
str = str .. " \\\\ " |
| 877 |
else |
| 878 |
str = str .. " \\\\ " |
| 879 |
end |
| 880 |
end |
| 881 |
return str .. "\\end{" .. format .. "} " |
| 882 |
end |
| 883 |
|
| 884 |
function matrix.chqeql(m1, m2) |
| 885 |
if #m1 ~= #m2 or #m1[1] ~= #m2[1] then |
| 886 |
return false |
| 887 |
end |
| 888 |
for i = 1, #m1 do |
| 889 |
for j = 1, #m1[1] do |
| 890 |
if not(lnumChqEql(m1[i][j],m2[i][j])) then |
| 891 |
return false |
| 892 |
end |
| 893 |
end |
| 894 |
end |
| 895 |
return true |
| 896 |
end |
| 897 |
|
| 898 |
-- Setting Meta-operations in the matrix module. |
| 899 |
matrix_meta.__tostring = function(...) |
| 900 |
return matrix.show(...) |
| 901 |
end |
| 902 |
|
| 903 |
matrix_meta.__add = function(...) |
| 904 |
return matrix.add(...) |
| 905 |
end |
| 906 |
|
| 907 |
matrix_meta.__sub = function(...) |
| 908 |
return matrix.sub(...) |
| 909 |
end |
| 910 |
|
| 911 |
matrix_meta.__mul = function(m1, m2) |
| 912 |
if getmetatable(m1) ~= matrix_meta then |
| 913 |
return matrix.mulnum(m2, m1) |
| 914 |
elseif getmetatable(m2) ~= matrix_meta then |
| 915 |
return matrix.mulnum(m1, m2) |
| 916 |
end |
| 917 |
return matrix.mul(m1, m2) |
| 918 |
end |
| 919 |
|
| 920 |
matrix_meta.__div = function(m1, m2) |
| 921 |
if getmetatable(m1) ~= matrix_meta then |
| 922 |
return matrix.mulnum(matrix.invert(m2), m1) |
| 923 |
elseif getmetatable(m2) ~= matrix_meta then |
| 924 |
return matrix.divnum(m1, m2) |
| 925 |
end |
| 926 |
return matrix.div(m1, m2) |
| 927 |
end |
| 928 |
|
| 929 |
matrix_meta.__unm = function(mtx) |
| 930 |
return matrix.mulnum(mtx, -1) |
| 931 |
end |
| 932 |
|
| 933 |
matrix_meta.__eq = function(...) |
| 934 |
return matrix.chqeql(...) |
| 935 |
end |
| 936 |
|
| 937 |
local option = { |
| 938 |
["*"] = function(m1) |
| 939 |
return matrix.conjugate(m1) |
| 940 |
end, |
| 941 |
["T"] = function(m1) |
| 942 |
return matrix.transpose(m1) |
| 943 |
end |
| 944 |
} |
| 945 |
matrix_meta.__pow = function(m1, opt) |
| 946 |
return option[opt] and option[opt](m1) or matrix.pow(m1, opt) |
| 947 |
end |
| 948 |
|
| 949 |
-- vector part |
| 950 |
|
| 951 |
vectors = {} -- global registry to store vectors. |
| 952 |
|
| 953 |
vector = {} --module. |
| 954 |
|
| 955 |
local vector_meta = {} |
| 956 |
-- Adding functions to the vector module. |
| 957 |
function vector.new(vector, rows, columns, n) |
| 958 |
if columns ~= "e" and columns ~= "zero" then |
| 959 |
local tbl = {} |
| 960 |
for i = 1, #rows do |
| 961 |
tbl[i] = rows[i] |
| 962 |
end |
| 963 |
return setmetatable(tbl, vector_meta) |
| 964 |
end |
| 965 |
local vec = {} |
| 966 |
if columns == "e" then |
| 967 |
for i = 1, rows do |
| 968 |
if i == n then |
| 969 |
vec[i] = 1 |
| 970 |
else |
| 971 |
vec[i] = 0 |
| 972 |
end |
| 973 |
end |
| 974 |
return setmetatable(vec, vector_meta) |
| 975 |
end |
| 976 |
|
| 977 |
if columns == "zero" then |
| 978 |
for i = 1, rows do |
| 979 |
vec[i] = 0 |
| 980 |
end |
| 981 |
return setmetatable(vec, vector_meta) |
| 982 |
end |
| 983 |
end |
| 984 |
|
| 985 |
setmetatable( |
| 986 |
vector, |
| 987 |
{__call = function(...) |
| 988 |
return vector.new(...) |
| 989 |
end} |
| 990 |
) |
| 991 |
|
| 992 |
function vector.add(v1, v2) |
| 993 |
if #v1 ~= #v2 then |
| 994 |
return error("Vectors should be of same dimension.") |
| 995 |
end |
| 996 |
local vec = {} |
| 997 |
for i = 1, #v1 do |
| 998 |
vec[i] = v1[i] + v2[i] |
| 999 |
end |
| 1000 |
return setmetatable(vec, vector_meta) |
| 1001 |
end |
| 1002 |
|
| 1003 |
function vector.sub(v1, v2) |
| 1004 |
if #v1 ~= #v2 then |
| 1005 |
return error("Vectors should be of same dimension.") |
| 1006 |
end |
| 1007 |
local vec = {} |
| 1008 |
for i = 1, #v1 do |
| 1009 |
vec[i] = v1[i] - v2[i] |
| 1010 |
end |
| 1011 |
return setmetatable(vec, vector_meta) |
| 1012 |
end |
| 1013 |
|
| 1014 |
function vector.dot(v1, v2) |
| 1015 |
if #v1 ~= #v2 then |
| 1016 |
return error("Vectors should be of same dimension") |
| 1017 |
end |
| 1018 |
local sum = 0 |
| 1019 |
for i = 1, #v1 do |
| 1020 |
sum = sum + v1[i] * complex.conjugate(complex(v2[i])) |
| 1021 |
end |
| 1022 |
return sum |
| 1023 |
end |
| 1024 |
|
| 1025 |
function vector.mulnum(v1, num) |
| 1026 |
local vec = {} |
| 1027 |
-- multiply elements with number |
| 1028 |
for i = 1, #v1 do |
| 1029 |
vec[i] = v1[i] * num |
| 1030 |
end |
| 1031 |
return setmetatable(vec, vector_meta) |
| 1032 |
end |
| 1033 |
|
| 1034 |
function vector.sumnorm(v1) |
| 1035 |
local norm = 0 |
| 1036 |
for i = 1, #v1 do |
| 1037 |
norm = norm + complex.abs(complex(v1[i])) |
| 1038 |
end |
| 1039 |
return norm |
| 1040 |
end |
| 1041 |
|
| 1042 |
function vector.euclidnorm(v1) |
| 1043 |
return complex.sqrt(vector.dot(v1, v1)) |
| 1044 |
end |
| 1045 |
|
| 1046 |
function vector.pnorm(v1, p) |
| 1047 |
if math.floor(p) ~= math.abs(p) or p <= 1 then |
| 1048 |
return error("Invalid value of p") |
| 1049 |
end |
| 1050 |
local sum = 0 |
| 1051 |
for i = 1, #v1 do |
| 1052 |
sum = sum + complex.abs(complex(v1[i])) ^ p |
| 1053 |
end |
| 1054 |
return sum ^ (1 / p) |
| 1055 |
end |
| 1056 |
|
| 1057 |
function vector.supnorm(v1) |
| 1058 |
local result = 0 |
| 1059 |
for i = 1, #v1 do |
| 1060 |
local e = complex.abs(complex(v1[i])) |
| 1061 |
if e > result then |
| 1062 |
result = e |
| 1063 |
end |
| 1064 |
end |
| 1065 |
return result |
| 1066 |
end |
| 1067 |
|
| 1068 |
function vector.cross(v1, v2) |
| 1069 |
if #v1 ~= 3 or #v2 ~= 3 then |
| 1070 |
return error("Vectors should be of dimension 3") |
| 1071 |
end |
| 1072 |
local vec = {} |
| 1073 |
vec[1] = v1[2] * v2[3] - v1[3] * v2[2] |
| 1074 |
vec[2] = v1[3] * v2[1] - v1[1] * v2[3] |
| 1075 |
vec[3] = v1[1] * v2[2] - v1[2] * v2[1] |
| 1076 |
return setmetatable(vec, vector_meta) |
| 1077 |
end |
| 1078 |
|
| 1079 |
function vector.createrandom(n, start, stop) |
| 1080 |
start = start or 0 |
| 1081 |
stop = stop or 10 |
| 1082 |
vec = {} |
| 1083 |
for i = 1, n do |
| 1084 |
vec[i] = math.random(start, stop) |
| 1085 |
vec[i] = vec[i] + math.min(math.random(), math.abs(vec[i] - start), math.abs(stop - vec[i])) |
| 1086 |
end |
| 1087 |
return setmetatable(vec, vector_meta) |
| 1088 |
end |
| 1089 |
|
| 1090 |
function vector.getcoordinate(vec, i) |
| 1091 |
if vec[i] then |
| 1092 |
return vec[i] |
| 1093 |
end |
| 1094 |
end |
| 1095 |
|
| 1096 |
function vector.setcoordinate(vec, i, val) |
| 1097 |
if vec[i] then |
| 1098 |
vec[i] = val |
| 1099 |
return val |
| 1100 |
end |
| 1101 |
end |
| 1102 |
|
| 1103 |
function vector.getangle(v1, v2) |
| 1104 |
if #v1 ~= #v2 then |
| 1105 |
return error("Vectors should be of same dimension") |
| 1106 |
end |
| 1107 |
local x = complex.get(vector.dot(v1, v2) / (vector.euclidnorm(v1) * vector.euclidnorm(v2))) |
| 1108 |
return math.acos(mathround(x, 15)) |
| 1109 |
end |
| 1110 |
|
| 1111 |
function vector.copy(v1) |
| 1112 |
local vec = {} |
| 1113 |
for i = 1, #v1 do |
| 1114 |
vec[i] = v1[i] |
| 1115 |
end |
| 1116 |
return setmetatable(vec, vector_meta) |
| 1117 |
end |
| 1118 |
|
| 1119 |
function vector.op(exp) |
| 1120 |
return load("return " .. exp, exp, "t", vectors)() |
| 1121 |
end |
| 1122 |
|
| 1123 |
function vector.process(v1) |
| 1124 |
--v1=load("return "..v1)() |
| 1125 |
return vector.mulnum(v1, 1) |
| 1126 |
end |
| 1127 |
|
| 1128 |
function vector.show(vec, dig) |
| 1129 |
vec = vector.process(vec) |
| 1130 |
local dig = dig or 6 |
| 1131 |
local str = "" |
| 1132 |
for i = 1, #vec do |
| 1133 |
if i == 1 then |
| 1134 |
str = str .. complex.round(complex(vec[i]), dig) |
| 1135 |
else |
| 1136 |
str = str .. "," .. complex.round(complex(vec[i]), dig) |
| 1137 |
end |
| 1138 |
end |
| 1139 |
return str .. "" |
| 1140 |
end |
| 1141 |
|
| 1142 |
function vector.parse(vec) |
| 1143 |
local tbl = {} |
| 1144 |
for i = 1, #vec do |
| 1145 |
tbl[i] = vec[i] |
| 1146 |
end |
| 1147 |
return "(" .. table.concat(tbl, ",") .. ")" |
| 1148 |
end |
| 1149 |
|
| 1150 |
function vector.gs(inptTbl, brckt, dignum) |
| 1151 |
local brcktR = "" |
| 1152 |
brckt = brckt or "round" |
| 1153 |
if brckt == "round" then |
| 1154 |
brcktL = "(" |
| 1155 |
brcktR = ")" |
| 1156 |
end |
| 1157 |
if brckt == "square" then |
| 1158 |
brcktL = "[" |
| 1159 |
brcktR = "]" |
| 1160 |
end |
| 1161 |
if brckt == "curly" then |
| 1162 |
brcktL = "\\{" |
| 1163 |
brcktR = "\\}" |
| 1164 |
end |
| 1165 |
|
| 1166 |
local tbl = {} |
| 1167 |
local str = "" |
| 1168 |
k = #inptTbl |
| 1169 |
|
| 1170 |
if complex.round(vector.euclidnorm(inptTbl[1])) ~= complex("0.0") then |
| 1171 |
tbl[1] = vector.mulnum(inptTbl[1], 1 / vector.euclidnorm(inptTbl[1])) |
| 1172 |
else |
| 1173 |
tbl[1] = vector.mulnum(inptTbl[1], 1) |
| 1174 |
end |
| 1175 |
setmetatable(tbl[1], vector_meta) |
| 1176 |
str = str .. "$\\left" .. brcktL .. vector.show(tbl[1], dignum) .. "\\right" .. brcktR.." $" |
| 1177 |
for i = 2, k do |
| 1178 |
tbl[i] = inptTbl[i] |
| 1179 |
setmetatable(tbl[i], vector_meta) |
| 1180 |
for j = 1, i - 1 do |
| 1181 |
setmetatable(tbl[j], vector_meta) |
| 1182 |
tbl[i] = vector.sub(tbl[i], vector.mulnum(tbl[j], vector.dot(tbl[i], tbl[j]))) |
| 1183 |
end |
| 1184 |
if complex.round(vector.euclidnorm(tbl[i])) ~= complex("0.0") then |
| 1185 |
tbl[i] = vector.mulnum(tbl[i], 1 / vector.euclidnorm(tbl[i])) |
| 1186 |
end |
| 1187 |
tbl[i] = vector.mulnum(tbl[i], 1.0) |
| 1188 |
str = str .. ", $\\left" .. brcktL .. vector.show(tbl[i], dignum) .. "\\right" .. brcktR.." $" |
| 1189 |
end |
| 1190 |
str = str |
| 1191 |
return str |
| 1192 |
end |
| 1193 |
|
| 1194 |
function vector.gsX(inptTbl, brckt, dignum) |
| 1195 |
local brcktR = "" |
| 1196 |
local cnt = 1 |
| 1197 |
brckt = brckt or "round" |
| 1198 |
if brckt == "round" then |
| 1199 |
brcktL = "\\left(" |
| 1200 |
brcktR = "\\right)$$" |
| 1201 |
end |
| 1202 |
if brckt == "square" then |
| 1203 |
brcktL = "\\left[" |
| 1204 |
brcktR = "\\right]$$" |
| 1205 |
end |
| 1206 |
if brckt == "curly" then |
| 1207 |
brcktL = "\\left\\{" |
| 1208 |
brcktR = "\\right\\}$$" |
| 1209 |
end |
| 1210 |
|
| 1211 |
local tbl = {} |
| 1212 |
local tmpTbl = {} |
| 1213 |
local str = "" |
| 1214 |
k = #inptTbl |
| 1215 |
str = str .. "\\ \\newline Take given vectors as $v_1,\\ldots, v_" .. k .. "$ in order." |
| 1216 |
|
| 1217 |
if complex.round(vector.euclidnorm(inptTbl[1])) ~= complex("0.0") then |
| 1218 |
tbl[1] = vector.mulnum(inptTbl[1], 1.0 / vector.euclidnorm(inptTbl[1])) |
| 1219 |
else |
| 1220 |
tbl[1] = vector.mulnum(inptTbl[1], 1.0) |
| 1221 |
end |
| 1222 |
setmetatable(tbl[1], vector_meta) |
| 1223 |
str = str .. "\\ \\newline Step " .. cnt .. ": $$ u_" .. cnt .. "=v_" .. cnt .. "=" |
| 1224 |
str = str .. brcktL .. vector.show(inptTbl[1], dignum) .. brcktR |
| 1225 |
str = str .. " $$ e_" .. cnt .. "=" |
| 1226 |
if complex.round(vector.euclidnorm(tbl[1])) ~= complex("0.0") then |
| 1227 |
str = str .. "\\frac{u_{" .. cnt .. "}}" .. "{||u_{" .. cnt .. "}||} =" |
| 1228 |
end |
| 1229 |
str = str .. brcktL .. vector.show(tbl[1], dignum) .. brcktR |
| 1230 |
for i = 2, k do |
| 1231 |
tbl[i] = inptTbl[i] |
| 1232 |
setmetatable(tbl[i], vector_meta) |
| 1233 |
for j = 1, i - 1 do |
| 1234 |
setmetatable(tbl[j], vector_meta) |
| 1235 |
tmpTbl[i] = vector.sub(tbl[i], vector.mulnum(tbl[j], vector.dot(tbl[i], tbl[j]))) |
| 1236 |
tbl[i] = vector.sub(tbl[i], vector.mulnum(tbl[j], vector.dot(tbl[i], tbl[j]))) |
| 1237 |
end |
| 1238 |
if complex.round(vector.euclidnorm(tbl[i])) ~= complex("0.0") then |
| 1239 |
tbl[i] = vector.mulnum(tbl[i], 1 / vector.euclidnorm(tbl[i])) |
| 1240 |
else |
| 1241 |
tbl[i] = vector.mulnum(tbl[i], 1.0) |
| 1242 |
end |
| 1243 |
|
| 1244 |
cnt = cnt + 1 |
| 1245 |
str = str .. " Step " .. cnt |
| 1246 |
str = str .. ": $$ u_" .. cnt .. "=" |
| 1247 |
str = str .. "v_" .. cnt .. "-\\sum_{j=1}^{" .. (cnt - 1) .. "}{{proj_{u_j}(v_" .. cnt .. ")}}=" |
| 1248 |
str = str .. brcktL .. vector.show(tmpTbl[i], dignum) .. brcktR |
| 1249 |
str = str .. " $$ e_" .. cnt .. "=" |
| 1250 |
if vector.euclidnorm(tbl[i]) ~= complex(0.0) then |
| 1251 |
str = str .. "\\frac{u_{" .. cnt .. "}}" .. "{||u_{" .. cnt .. "}||} =" |
| 1252 |
end |
| 1253 |
str = str .. brcktL .. vector.show(tbl[i], dignum) .. brcktR |
| 1254 |
end |
| 1255 |
|
| 1256 |
return str |
| 1257 |
end |
| 1258 |
|
| 1259 |
function vector.chqeql(v1, v2) |
| 1260 |
if #v1 ~= #v2 then |
| 1261 |
return false |
| 1262 |
end |
| 1263 |
for j = 1, #v1 do |
| 1264 |
if not(lnumChqEql(v1[j],v2[j])) then |
| 1265 |
return false |
| 1266 |
end |
| 1267 |
end |
| 1268 |
return true |
| 1269 |
end |
| 1270 |
-- Setting Meta-operations in the vector module. |
| 1271 |
vector_meta.__tostring = function(...) |
| 1272 |
return vector.show(...) |
| 1273 |
end |
| 1274 |
|
| 1275 |
vector_meta.__add = function(...) |
| 1276 |
return vector.add(...) |
| 1277 |
end |
| 1278 |
|
| 1279 |
vector_meta.__sub = function(...) |
| 1280 |
return vector.sub(...) |
| 1281 |
end |
| 1282 |
|
| 1283 |
vector_meta.__unm = function(vec) |
| 1284 |
return vector.mulnum(vec, -1) |
| 1285 |
end |
| 1286 |
|
| 1287 |
vector_meta.__eq = function(...) |
| 1288 |
return vector.chqeql(...) |
| 1289 |
end |
| 1290 |
|
| 1291 |
vector_meta.__mul = function(v1, v2) |
| 1292 |
if getmetatable(v1) ~= vector_meta then |
| 1293 |
return vector.mulnum(v2, v1) |
| 1294 |
elseif getmetatable(v2) ~= vector_meta then |
| 1295 |
return vector.mulnum(v1, v2) |
| 1296 |
end |
| 1297 |
return vector.dot(v1, v2) |
| 1298 |
end |
| 1299 |
|
| 1300 |
function mathround(num, numDecimalPlaces) |
| 1301 |
local mult = 10 ^ (numDecimalPlaces or 0) |
| 1302 |
return math.floor(num * mult + 0.5) / mult |
| 1303 |
end |
| 1304 |
|
| 1305 |
|
| 1306 |
\end{luacode*} |
| 1307 |
|
| 1308 |
% matrix latex commands |
| 1309 |
|
| 1310 |
\newcommand\matrixNew[2]{% |
| 1311 |
\directlua{% |
| 1312 |
matrices['#1'] = matrix(#2) |
| 1313 |
}% |
| 1314 |
} |
| 1315 |
|
| 1316 |
% ========= KEY DEFINITIONS ========= |
| 1317 |
\define@key{matrixop}{type}{\def\mop@type{#1}} |
| 1318 |
\define@key{matrixop}{truncate}{\def\mop@truncate{#1}} |
| 1319 |
% ========= KEY DEFAULTS ========= |
| 1320 |
\setkeys{matrixop}{type=bmatrix,truncate=6}% |
| 1321 |
|
| 1322 |
\newcommand{\matrixPrint}[2][]{% |
| 1323 |
\begingroup% |
| 1324 |
\setkeys{matrixop}{#1} |
| 1325 |
\directlua{tex.sprint(matrix.show(matrices['#2'],"\mop@type",\mop@truncate))} |
| 1326 |
% |
| 1327 |
\endgroup% |
| 1328 |
} |
| 1329 |
|
| 1330 |
\newcommand\matrixOp[2]{% |
| 1331 |
\directlua{% |
| 1332 |
matrices['#1'] = matrix.op('#2') |
| 1333 |
}% |
| 1334 |
} |
| 1335 |
|
| 1336 |
|
| 1337 |
\newcommand\matrixAdd[3]{% |
| 1338 |
\directlua{% |
| 1339 |
matrices['#1'] = matrix.add(matrices['#2'],matrices['#3']) |
| 1340 |
}% |
| 1341 |
} |
| 1342 |
|
| 1343 |
\newcommand\matrixSub[3]{% |
| 1344 |
\directlua{% |
| 1345 |
matrices['#1'] = matrix.sub(matrices['#2'],matrices['#3']) |
| 1346 |
}% |
| 1347 |
} |
| 1348 |
|
| 1349 |
\newcommand\matrixMulNum[3]{% |
| 1350 |
\directlua{% |
| 1351 |
matrices['#1'] = matrix.mulnum(matrices['#3'],#2) |
| 1352 |
}% |
| 1353 |
} |
| 1354 |
|
| 1355 |
\newcommand\matrixMul[3]{% |
| 1356 |
\directlua{% |
| 1357 |
matrices['#1'] = matrix.mul(matrices['#2'],matrices['#3']) |
| 1358 |
}% |
| 1359 |
} |
| 1360 |
|
| 1361 |
\newcommand\matrixSwapRows[4]{% |
| 1362 |
\directlua{% |
| 1363 |
matrices['#1'] = matrix.swapRows(matrices['#2'],#3,#4) |
| 1364 |
}% |
| 1365 |
} |
| 1366 |
|
| 1367 |
\newcommand\matrixSwapCols[4]{% |
| 1368 |
\directlua{% |
| 1369 |
matrices['#1'] = matrix.swapCols(matrices['#2'],#3,#4) |
| 1370 |
}% |
| 1371 |
} |
| 1372 |
|
| 1373 |
\newcommand\matrixMulRow[4]{% |
| 1374 |
\directlua{% |
| 1375 |
matrices['#1'] = matrix.mulRow(matrices['#2'],#3,#4) |
| 1376 |
}% |
| 1377 |
} |
| 1378 |
|
| 1379 |
\newcommand\matrixMulCol[4]{% |
| 1380 |
\directlua{% |
| 1381 |
matrices['#1'] = matrix.mulCol(matrices['#2'],#3,#4) |
| 1382 |
}% |
| 1383 |
} |
| 1384 |
|
| 1385 |
\newcommand\matrixMulAddRow[5]{% |
| 1386 |
\directlua{% |
| 1387 |
matrices['#1'] = matrix.mulAddRow(matrices['#2'],#4,#3,#5) |
| 1388 |
}% |
| 1389 |
} |
| 1390 |
|
| 1391 |
\newcommand\matrixMulAddCol[5]{% |
| 1392 |
\directlua{% |
| 1393 |
matrices['#1'] = matrix.mulAddCol(matrices['#2'],#4,#3,#5) |
| 1394 |
}% |
| 1395 |
} |
| 1396 |
|
| 1397 |
\newcommand\matrixTranspose[2]{% |
| 1398 |
\directlua{% |
| 1399 |
matrices['#1'] = matrix.transpose(matrices['#2']) |
| 1400 |
}% |
| 1401 |
} |
| 1402 |
|
| 1403 |
\newcommand\matrixSubmatrix[6]{% |
| 1404 |
\directlua{% |
| 1405 |
matrices['#1'] = matrix.subm(matrices['#2'],#3,#4,#5,#6) |
| 1406 |
}% |
| 1407 |
} |
| 1408 |
|
| 1409 |
\newcommand\matrixConcatH[3]{% |
| 1410 |
\directlua{% |
| 1411 |
matrices['#1'] = matrix.concath(matrices['#2'],matrices['#3']) |
| 1412 |
}% |
| 1413 |
} |
| 1414 |
|
| 1415 |
\newcommand\matrixConcatV[3]{% |
| 1416 |
\directlua{% |
| 1417 |
matrices['#1'] = matrix.concatv(matrices['#2'],matrices['#3']) |
| 1418 |
}% |
| 1419 |
} |
| 1420 |
|
| 1421 |
\newcommand\matrixNumRows[1]{% |
| 1422 |
\directlua{% |
| 1423 |
tex.sprint(tostring(matrix.rows(matrices['#1']))) |
| 1424 |
}% |
| 1425 |
} |
| 1426 |
|
| 1427 |
\newcommand\matrixNumCols[1]{% |
| 1428 |
\directlua{% |
| 1429 |
tex.sprint(tostring(matrix.columns(matrices['#1']))) |
| 1430 |
}% |
| 1431 |
} |
| 1432 |
|
| 1433 |
\newcommand\matrixGetElement[3]{% |
| 1434 |
\directlua{% |
| 1435 |
tex.sprint(tostring(matrix.getelement(matrices['#1'],#2,#3))) |
| 1436 |
}% |
| 1437 |
} |
| 1438 |
|
| 1439 |
\newcommand\matrixSetElement[4]{% |
| 1440 |
\directlua{% |
| 1441 |
matrix.setelement(matrices['#1'],#2,#3,#4) |
| 1442 |
}% |
| 1443 |
} |
| 1444 |
|
| 1445 |
\newcommand\matrixInvert[2]{% |
| 1446 |
\directlua{% |
| 1447 |
matrices['#1'] = matrix.invert(matrices['#2']) |
| 1448 |
}% |
| 1449 |
} |
| 1450 |
|
| 1451 |
\newcommand\matrixPow[3]{% |
| 1452 |
\directlua{% |
| 1453 |
matrices['#1'] = matrix.pow(matrices['#2'],#3) |
| 1454 |
}% |
| 1455 |
} |
| 1456 |
|
| 1457 |
\newcommand\matrixCreateRandom[5]{% |
| 1458 |
\directlua{% |
| 1459 |
matrices['#1'] = matrix.createrandom(#2,#3,#4,#5) |
| 1460 |
}% |
| 1461 |
} |
| 1462 |
|
| 1463 |
\newcommand\matrixDet[1]{% |
| 1464 |
\directlua{% |
| 1465 |
tex.sprint(tostring(matrix.det(matrices['#1']))) |
| 1466 |
}% |
| 1467 |
} |
| 1468 |
|
| 1469 |
\newcommand\matrixTrace[1]{% |
| 1470 |
\directlua{% |
| 1471 |
tex.sprint(tostring(matrix.trace(matrices['#1']))) |
| 1472 |
}% |
| 1473 |
} |
| 1474 |
|
| 1475 |
\newcommand\matrixNormOne[1]{% |
| 1476 |
\directlua{% |
| 1477 |
tex.sprint(tostring(matrix.norm1(matrices['#1']))) |
| 1478 |
}% |
| 1479 |
} |
| 1480 |
|
| 1481 |
\newcommand\matrixNormInfty[1]{% |
| 1482 |
\directlua{% |
| 1483 |
tex.sprint(tostring(matrix.norminfty(matrices['#1']))) |
| 1484 |
}% |
| 1485 |
} |
| 1486 |
|
| 1487 |
\newcommand\matrixNormMax[1]{% |
| 1488 |
\directlua{% |
| 1489 |
tex.sprint(tostring(matrix.normmax(matrices['#1']))) |
| 1490 |
}% |
| 1491 |
} |
| 1492 |
|
| 1493 |
\newcommand\matrixNormF[1]{% |
| 1494 |
\directlua{% |
| 1495 |
tex.sprint(tostring(matrix.normF(matrices['#1']))) |
| 1496 |
}% |
| 1497 |
} |
| 1498 |
|
| 1499 |
\newcommand\matrixCopy[2]{% |
| 1500 |
\directlua{% |
| 1501 |
matrices['#1'] = matrix.copy(matrices['#2']) |
| 1502 |
}% |
| 1503 |
} |
| 1504 |
|
| 1505 |
\newcommand\matrixRREF[2]{% |
| 1506 |
\directlua{% |
| 1507 |
matrices['#1'] = matrix.rref(matrices['#2']) |
| 1508 |
}% |
| 1509 |
} |
| 1510 |
|
| 1511 |
\newcommand\matrixConjugate[2]{% |
| 1512 |
\directlua{% |
| 1513 |
matrices['#1'] = matrix.conjugate(matrices['#2']) |
| 1514 |
}% |
| 1515 |
} |
| 1516 |
|
| 1517 |
\newcommand\matrixConjugateT[2]{% |
| 1518 |
\directlua{% |
| 1519 |
matrices['#1'] = matrix.conjugateT(matrices['#2']) |
| 1520 |
}% |
| 1521 |
} |
| 1522 |
|
| 1523 |
\newcommand\matrixRank[1]{% |
| 1524 |
\directlua{% |
| 1525 |
tex.sprint(tostring(matrix.rank(matrices['#1']))) |
| 1526 |
}% |
| 1527 |
} |
| 1528 |
|
| 1529 |
\newcommand\matrixEql[2]{% |
| 1530 |
\directlua{% |
| 1531 |
tex.sprint(tostring(matrix.chqeql(matrices['#1'],matrices['#2']))) |
| 1532 |
}% |
| 1533 |
} |
| 1534 |
|
| 1535 |
% ========= KEY DEFINITIONS ========= |
| 1536 |
\define@key{matrixrr}{type}{\def\moprr@type{#1}} |
| 1537 |
\define@key{matrixrr}{truncate}{\def\moprr@truncate{#1}} |
| 1538 |
|
| 1539 |
% ========= KEY DEFAULTS ========= |
| 1540 |
\setkeys{matrixrr}{type=bmatrix,truncate=6}% |
| 1541 |
|
| 1542 |
\newcommand{\matrixRREFSteps}[2][]{% |
| 1543 |
\begingroup% |
| 1544 |
\setkeys{matrixrr}{#1} |
| 1545 |
\directlua{% |
| 1546 |
tex.sprint(matrix.rref0E(matrices['#2'],"\moprr@type",\moprr@truncate))} |
| 1547 |
% |
| 1548 |
\endgroup% |
| 1549 |
} |
| 1550 |
|
| 1551 |
\newcommand\matrixGaussJordan[3]{% |
| 1552 |
\directlua{% |
| 1553 |
matrices['#1'] = matrix.GaussJordan(matrices['#2'],matrices['#3']) |
| 1554 |
}% |
| 1555 |
} |
| 1556 |
|
| 1557 |
\newcommand{\matrixGaussJordanSteps}[3][]{% |
| 1558 |
\begingroup% |
| 1559 |
\setkeys{matrixrr}{#1} |
| 1560 |
\directlua{% |
| 1561 |
tex.sprint(matrix.gauss0E(matrices['#2'],matrices['#3'],"\moprr@type",\moprr@truncate))} |
| 1562 |
% |
| 1563 |
\endgroup% |
| 1564 |
} |
| 1565 |
|
| 1566 |
% vector latex commands |
| 1567 |
|
| 1568 |
\newcommand\vectorNew[2]{% |
| 1569 |
\directlua{% |
| 1570 |
vectors['#1'] = vector(#2) |
| 1571 |
}% |
| 1572 |
} |
| 1573 |
|
| 1574 |
% ========= KEY DEFINITIONS ========= |
| 1575 |
\define@key{vectorop}{truncate}{\def\vop@truncate{#1}} |
| 1576 |
|
| 1577 |
% ========= KEY DEFAULTS ========= |
| 1578 |
\setkeys{vectorop}{truncate=6}% |
| 1579 |
|
| 1580 |
\newcommand{\vectorPrint}[2][]{% |
| 1581 |
\begingroup% |
| 1582 |
\setkeys{vectorop}{#1} |
| 1583 |
\directlua{tex.sprint(vector.show(vectors['#2'],\vop@truncate))} |
| 1584 |
% |
| 1585 |
\endgroup% |
| 1586 |
} |
| 1587 |
|
| 1588 |
\newcommand\vectorParse[1]{% |
| 1589 |
\directlua{% |
| 1590 |
tex.sprint(tostring(vector.parse(vectors['#1']))) |
| 1591 |
}% |
| 1592 |
} |
| 1593 |
|
| 1594 |
\newcommand\vectorOp[2]{% |
| 1595 |
\directlua{% |
| 1596 |
vectors['#1'] = vector.op('#2') |
| 1597 |
}% |
| 1598 |
} |
| 1599 |
|
| 1600 |
\newcommand\vectorAdd[3]{% |
| 1601 |
\directlua{% |
| 1602 |
vectors['#1'] = vector.add(vectors['#2'],vectors['#3']) |
| 1603 |
}% |
| 1604 |
} |
| 1605 |
|
| 1606 |
\newcommand\vectorSub[3]{% |
| 1607 |
\directlua{% |
| 1608 |
vectors['#1'] = vector.sub(vectors['#2'],vectors['#3']) |
| 1609 |
}% |
| 1610 |
} |
| 1611 |
|
| 1612 |
\newcommand\vectorDot[2]{% |
| 1613 |
\directlua{% |
| 1614 |
tex.sprint(tostring(vector.dot(vectors['#1'],vectors['#2']))) |
| 1615 |
}% |
| 1616 |
} |
| 1617 |
|
| 1618 |
\newcommand\vectorMulNum[3]{% |
| 1619 |
\directlua{% |
| 1620 |
vectors['#1'] = vector.mulnum(vectors['#2'],#3) |
| 1621 |
}% |
| 1622 |
} |
| 1623 |
|
| 1624 |
\newcommand\vectorCross[3]{% |
| 1625 |
\directlua{% |
| 1626 |
vectors['#1'] = vector.cross(vectors['#2'],vectors['#3']) |
| 1627 |
}% |
| 1628 |
} |
| 1629 |
|
| 1630 |
\newcommand\vectorSumNorm[1]{% |
| 1631 |
\directlua{% |
| 1632 |
tex.sprint(tostring(vector.sumnorm(vectors['#1']))) |
| 1633 |
}% |
| 1634 |
} |
| 1635 |
|
| 1636 |
\newcommand\vectorEuclidNorm[1]{% |
| 1637 |
\directlua{% |
| 1638 |
tex.sprint(tostring(vector.euclidnorm(vectors['#1']))) |
| 1639 |
}% |
| 1640 |
} |
| 1641 |
|
| 1642 |
\newcommand\vectorSupNorm[1]{% |
| 1643 |
\directlua{% |
| 1644 |
tex.sprint(tostring(vector.supnorm(vectors['#1']))) |
| 1645 |
}% |
| 1646 |
} |
| 1647 |
|
| 1648 |
\newcommand\vectorpNorm[2]{% |
| 1649 |
\directlua{% |
| 1650 |
tex.sprint(tostring(vector.pnorm(vectors['#1'],#2))) |
| 1651 |
}% |
| 1652 |
} |
| 1653 |
|
| 1654 |
\newcommand\vectorCreateRandom[4]{% |
| 1655 |
\directlua{% |
| 1656 |
vectors['#1'] = vector.createrandom(#2,#3,#4) |
| 1657 |
}% |
| 1658 |
} |
| 1659 |
|
| 1660 |
\newcommand\vectorCopy[2]{% |
| 1661 |
\directlua{% |
| 1662 |
vectors['#1'] = vector.copy(vectors['#2']) |
| 1663 |
}% |
| 1664 |
} |
| 1665 |
|
| 1666 |
\newcommand\vectorGetCoordinate[2]{% |
| 1667 |
\directlua{% |
| 1668 |
tex.sprint(tostring(vector.getcoordinate(vectors['#1'],#2))) |
| 1669 |
}% |
| 1670 |
} |
| 1671 |
|
| 1672 |
\newcommand\vectorSetCoordinate[3]{% |
| 1673 |
\directlua{% |
| 1674 |
tex.sprint(tostring(vector.setcoordinate(vectors['#1'],#2,#3))) |
| 1675 |
}% |
| 1676 |
} |
| 1677 |
|
| 1678 |
\newcommand\vectorGetAngle[2]{% |
| 1679 |
\directlua{% |
| 1680 |
tex.sprint(tostring(vector.getangle(vectors['#1'],vectors['#2']))) |
| 1681 |
}% |
| 1682 |
} |
| 1683 |
|
| 1684 |
\newcommand\vectorEql[2]{% |
| 1685 |
\directlua{% |
| 1686 |
tex.sprint(tostring(vector.chqeql(vectors['#1'],vectors['#2']))) |
| 1687 |
}% |
| 1688 |
} |
| 1689 |
|
| 1690 |
% ========= KEY DEFINITIONS ========= |
| 1691 |
\define@key{vecrr}{brckt}{\def\voprr@brckt{#1}} |
| 1692 |
\define@key{vecrr}{truncate}{\def\voprr@truncate{#1}} |
| 1693 |
|
| 1694 |
% ========= KEY DEFAULTS ========= |
| 1695 |
\setkeys{vecrr}{brckt=round,truncate=6}% |
| 1696 |
\newcommand{\vectorGramSchmidt}[2][]{% |
| 1697 |
\begingroup% |
| 1698 |
\setkeys{vecrr}{#1} |
| 1699 |
\directlua{% |
| 1700 |
local tbl = #2 |
| 1701 |
local outTbl={} |
| 1702 |
local sum = 0 |
| 1703 |
for i=1,table.getn(tbl) do |
| 1704 |
outTbl[i] = vectors[tbl[i]] |
| 1705 |
end |
| 1706 |
|
| 1707 |
tex.sprint(vector.gs(outTbl,"\voprr@brckt",\voprr@truncate))} |
| 1708 |
% |
| 1709 |
\endgroup% |
| 1710 |
} |
| 1711 |
|
| 1712 |
\newcommand{\vectorGramSchmidtSteps}[2][]{% |
| 1713 |
\begingroup% |
| 1714 |
\setkeys{vecrr}{#1} |
| 1715 |
\directlua{% |
| 1716 |
local tbl = #2 |
| 1717 |
local outTbl={} |
| 1718 |
local sum = 0 |
| 1719 |
for i=1,table.getn(tbl) do |
| 1720 |
outTbl[i] = vectors[tbl[i]] |
| 1721 |
end |
| 1722 |
tex.sprint(vector.gsX(outTbl,"\voprr@brckt",\voprr@truncate))} |
| 1723 |
% |
| 1724 |
\endgroup% |
| 1725 |
} |
| 1726 |
|
| 1727 |
\endinput |