Calculating a determinant in Lua - math

I'm trying to calculate determinants with any order using Lua. I can calculate determinants for order less than 4, but not for greater equals than 4 ones.
I have a 4x4 matrix and its determinant with the program is 0, but the real solution is 56.
I don't know if the problem is in getSubmatrix method or is in detMat method, because I don't have any error message from the console.
I've ported the methods from my own java code, where it works fine.
Here's all my code:
function numMat(n, A)
local S = {}
for i = 1, #A, 1 do
local T = {}
S[i] = T
for j =1, #A[1], 1 do
T[j] = n * A[i][j]
end
end
return S
end
function sumMat(A, B)
local C = {}
for i = 1, #A do
local D = {}
C[i] = D
for j = 1, #A[1] do
D[j] = A[i][j] + B[i][j]
end
end
return C
end
function subMat(A, B)
return sumMat(A, numMat(-1, B))
end
function printMatrix(A)
for i, v in ipairs(A) do
for j, w in ipairs(v) do
print(w)
end
end
end
function escalarProduct(u, v)
local w = 0
for i = 1, #u do
w = w + u[i] * v[i]
end
return w
end
function prodMat(A, B)
local C = {}
for i = 1, #A do
C[i] = {}
for j = 1, #B[1] do
local num = A[i][1] * B[1][j]
for k = 2, #A[1] do
num = num + A[i][k] * B[k][j]
end
C[i][j] = num
end
end
return C
end
function powMat(A, power)
local B = {}
local C = {}
C = A
for i = 1, power - 1 do
B = prodMat(C, A)
C = B
end
return B
end
function trasposeMat(A)
local B = {}
for i = 1, #A do
local C = {}
B[i] = C
for j = 1, #A[1] do
C[j] = A[j][i]
end
end
return B
end
function productDiag(m)
local prod = 1
for i = 1, #m do
for j = 1, #m do
if i == j then prod = prod * m[i][i] end
end
end
return prod
end
function isDiagonal(A)
for i = 1, #A do
for j = 1, #A do
if i ~= j and A[i][j] ~= 0 then return false end
end
end
return true
end
function isTriangSup(m)
for i = 1, #m do
for j = 1, i do
if m[i][j] == 0 then return true end
end
end
return false
end
function isTriangInf(m)
return isTriangSup(trasposeMat(m))
end
function isTriang(m)
if(isTriangSup(m)) then return true
else
return false
end
end
function getSubmatrix(A, rows, cols, col)
local submatrix = {}
local k = 1
for j = 1, cols do
--local D = {}
--submatrix[j] = D
if j == col then
break
end
for i = 2, rows do
submatrix[i-1][k] = A[i][j]
--D[k] = A[i][j]
end
k = k + 1
end
return submatrix
end
function det2Mat(A)
assert(#A == 2 and #A == #A[1], 'Error: The matrix must be squared, order 2.')
return A[1][1] * A[2][2] - A[1][2] * A[2][1]
end
function det3Mat(A)
assert(#A == 3 and #A == #A[1], 'Error: The matrix must be squared, order 3.')
s1 = A[1][1] * A[2][2] * A[3][3] + A[2][1] * A[3][2] * A[1][3] + A[1][2] * A[2][3] * A[3][1]
s2 = A[1][3] * A[2][2] * A[3][1] + A[1][2] * A[2][1] * A[3][3] + A[2][3] * A[3][2] * A[1][1]
return s1 - s2
end
function detMat(A)
local submatrix = {}
local det
local sign = 1
local rows = #A
local cols = #A[1]
assert(rows == cols, 'Error: The matrix must be squared.')
if rows == 1 then
return A[1][1]
end
if rows == 2 then
return det2Mat(A)
end
if rows == 3 then
return det3Mat(A)
end
if isDiagonal(A) or isTriang(A) then return productDiag(A) end
if rows > 3 then
for column = 1, cols do
submatrix = getSubmatrix(A, rows, cols, column)
det = det + sign * A[1][column] * detMat(submatrix)
sign = -sign
end
end
return det
end
A = {{1, 3}, {5, 6}}
B = {{2, 4}, {3, 1}}
C = {{2, 3, 4}, {-5, 4, 7}, {7, 1, 0}}
D = {{2, 0, 0, 0}, {0, 4, 0, 0}, {0, 0, 7, 0}, {0, 0, 0, 6}}
E = {{2, 3, 4, -3}, {-5, 4, 7, -2}, {7, 1, 0, 5}, {3, 4, 5, 6}}
--printMatrix(numMat(-1, A))
--printMatrix(sumMat(A, B))
--printMatrix(subMat(A, B))
--print(escalarProduct({1, 3}, {5, 6}))
--printMatrix(prodMat(A, B))
--printMatrix(trasposeMat(A))
--printMatrix(powMat(A, 2))
--printMatrix(powMat(A, 3))
print(detMat(A))
print(detMat(B))
print(detMat(C))
print(detMat(D))
print(detMat(E)) --The solution must be 56
And the console solution is:
-9
-10
1
336
0
The error is when I want to find out the determinant of the matrix E.

Related

Error: subscript out of bounds (knight's tour)

im new to R and im trying to solve for the minimum number of moves for a knight visit all the moves in a chess board.
I got the python code from:
https://www.geeksforgeeks.org/the-knights-tour-problem-backtracking-1/
and i tried to translate it to r.
But i am always getting the error and I don't know where I went wrong.
This is my code:
chess = rep(-1, times = 64)
board = matrix(data = chess, nrow = 8, ncol = 8, byrow = TRUE)
move_x = c(2, 1, -1, -2, -2, -1, 1, 2)
move_y = c(1, 2, 2, 1, -1, -2, -2, -1)
board[1, 1] = 0
pos = 1
valid_move <- function (x, y, board) {
if (x >= 1 & y >= 1 & x <= 8 & y <= 8 & board[x, y] == -1) {
return (T)
}
return (F)
}
solve <- function (board, curr_x, curr_y, move_x, move_y, pos) {
if (pos == 64) {
return (T)
}
for (i in seq(1:8)) {
new_x = curr_x + move_x[i]
new_y = curr_y + move_y[i]
if (valid_move(new_x, new_y, board)) {
board[new_x, new_y] = pos
if (solve(board, new_x, new_y, move_x, move_y, pos+1)) {
return (TRUE)
}
board[new_x, new_y] = -1
}
}
}
main <- function() {
sims = 10
ctr = 0
number_of_moves = c()
solve(board, 1, 1, move_x, move_y, pos)
print(paste("Minimum number of moves: ", pos))
}
main()
Thanks!
The problem is that the python code relies on short-circuiting to prevent out-of-bounds errors. & will not short-circuit so you need to use &&.
Here is an example
FALSE && stop()
#> [1] FALSE
FALSE & stop()
#> Error:
Update valid_move to this
valid_move <- function (x, y, board) {
# Changed to && to allow short-circuiting
# if (x >= 1 & y >= 1 & x <= 8 & y <= 8 & board[x, y] == -1) {
if (x >= 1 && y >= 1 && x <= 8 && y <= 8 && board[x, y] == -1) {
return (T)
}
return (F)
}

Angular 7 lava effect animation

I have an Angular 7 app with a home page containing a large coloured block (enough to fill the page) at the top with a header and some images. I want to put some lava effect animations into the background similar to this
code in case link is removed:
HTML:
<canvas id="lamp-anim" class="lamp-anim" width="1034" height="613"></canvas>
CSS:
body {
background: #f857a6; /* fallback for old browsers */
background: -webkit-linear-gradient(to top, #ff5858, #f857a6); /* Chrome
10-25, Safari 5.1-6 */
background: linear-gradient(to top, #ff5858, #f857a6); /* W3C, IE 10+/
Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
}
JS:
window.lavaAnimation = function() {
"use strict";
var t, i = {
screen: {
elem: null,
callback: null,
ctx: null,
width: 0,
height: 0,
left: 0,
top: 0,
init: function(t, i, s) {
return this.elem = document.getElementById(t), this.callback = i || null, "CANVAS" == this.elem.tagName && (this.ctx = this.elem.getContext("2d")), window.addEventListener("resize", function() {
this.resize()
}.bind(this), !1), this.elem.onselectstart = function() {
return !1
}, this.elem.ondrag = function() {
return !1
}, s && this.resize(), this
},
resize: function() {
var t = this.elem;
for (this.width = t.offsetWidth, this.height = t.offsetHeight, this.left = 0, this.top = 0; null != t; t = t.offsetParent) this.left += t.offsetLeft, this.top += t.offsetTop;
this.ctx && (this.elem.width = this.width, this.elem.height = this.height), this.callback && this.callback()
}
}
},
s = function(t, i) {
this.x = t, this.y = i, this.magnitude = t * t + i * i, this.computed = 0, this.force = 0
};
s.prototype.add = function(t) {
return new s(this.x + t.x, this.y + t.y)
};
var h = function(t) {
var i = .1,
h = 1.5;
this.vel = new s((Math.random() > .5 ? 1 : -1) * (.2 + .25 * Math.random()), (Math.random() > .5 ? 1 : -1) * (.2 + Math.random())), this.pos = new s(.2 * t.width + Math.random() * t.width * .6, .2 * t.height + Math.random() * t.height * .6), this.size = t.wh / 15 + (Math.random() * (h - i) + i) * (t.wh / 15), this.width = t.width, this.height = t.height
};
h.prototype.move = function() {
this.pos.x >= this.width - this.size ? (this.vel.x > 0 && (this.vel.x = -this.vel.x), this.pos.x = this.width - this.size) : this.pos.x <= this.size && (this.vel.x < 0 && (this.vel.x = -this.vel.x), this.pos.x = this.size), this.pos.y >= this.height - this.size ? (this.vel.y > 0 && (this.vel.y = -this.vel.y), this.pos.y = this.height - this.size) : this.pos.y <= this.size && (this.vel.y < 0 && (this.vel.y = -this.vel.y), this.pos.y = this.size), this.pos = this.pos.add(this.vel)
};
var e = function(t, i, e, n, a) {
this.step = 5, this.width = t, this.height = i, this.wh = Math.min(t, i), this.sx = Math.floor(this.width / this.step), this.sy = Math.floor(this.height / this.step), this.paint = !1, this.metaFill = r(t, i, t, n, a), this.plx = [0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0], this.ply = [0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1], this.mscases = [0, 3, 0, 3, 1, 3, 0, 3, 2, 2, 0, 2, 1, 1, 0], this.ix = [1, 0, -1, 0, 0, 1, 0, -1, -1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1], this.grid = [], this.balls = [], this.iter = 0, this.sign = 1;
for (var o = 0; o < (this.sx + 2) * (this.sy + 2); o++) this.grid[o] = new s(o % (this.sx + 2) * this.step, Math.floor(o / (this.sx + 2)) * this.step);
for (var l = 0; e > l; l++) this.balls[l] = new h(this)
};
e.prototype.computeForce = function(t, i, s) {
var h, e = s || t + i * (this.sx + 2);
if (0 === t || 0 === i || t === this.sx || i === this.sy) h = .6 * this.sign;
else {
h = 0;
for (var r, n = this.grid[e], a = 0; r = this.balls[a++];) h += r.size * r.size / (-2 * n.x * r.pos.x - 2 * n.y * r.pos.y + r.pos.magnitude + n.magnitude);
h *= this.sign
}
return this.grid[e].force = h, h
}, e.prototype.marchingSquares = function(t) {
var i = t[0],
s = t[1],
h = t[2],
e = i + s * (this.sx + 2);
if (this.grid[e].computed === this.iter) return !1;
for (var r, n = 0, a = 0; 4 > a; a++) {
var l = i + this.ix[a + 12] + (s + this.ix[a + 16]) * (this.sx + 2),
d = this.grid[l].force;
(d > 0 && this.sign < 0 || 0 > d && this.sign > 0 || !d) && (d = this.computeForce(i + this.ix[a + 12], s + this.ix[a + 16], l)), Math.abs(d) > 1 && (n += Math.pow(2, a))
}
if (15 === n) return [i, s - 1, !1];
5 === n ? r = 2 === h ? 3 : 1 : 10 === n ? r = 3 === h ? 0 : 2 : (r = this.mscases[n], this.grid[e].computed = this.iter);
var p = this.step / (Math.abs(Math.abs(this.grid[i + this.plx[4 * r + 2] + (s + this.ply[4 * r + 2]) * (this.sx + 2)].force) - 1) / Math.abs(Math.abs(this.grid[i + this.plx[4 * r + 3] + (s + this.ply[4 * r + 3]) * (this.sx + 2)].force) - 1) + 1);
return o.lineTo(this.grid[i + this.plx[4 * r] + (s + this.ply[4 * r]) * (this.sx + 2)].x + this.ix[r] * p, this.grid[i + this.plx[4 * r + 1] + (s + this.ply[4 * r + 1]) * (this.sx + 2)].y + this.ix[r + 4] * p), this.paint = !0, [i + this.ix[r + 4], s + this.ix[r + 8], r]
}, e.prototype.renderMetaballs = function() {
for (var t, i = 0; t = this.balls[i++];) t.move();
for (this.iter++, this.sign = -this.sign, this.paint = !1, o.fillStyle = this.metaFill, o.beginPath(), i = 0; t = this.balls[i++];) {
var s = [Math.round(t.pos.x / this.step), Math.round(t.pos.y / this.step), !1];
do s = this.marchingSquares(s); while (s);
this.paint && (o.fill(), o.closePath(), o.beginPath(), this.paint = !1)
}
};
var r = function(t, i, s, h, e) {
var r = o.createRadialGradient(t / 1, i / 1, 0, t / 1, i / 1, s);
return r.addColorStop(0, h), r.addColorStop(1, e), r
};
if (document.getElementById("lamp-anim")) {
var n = function() {
requestAnimationFrame(n), o.clearRect(0, 0, a.width, a.height), t.renderMetaballs()
},
a = i.screen.init("lamp-anim", null, !0),
o = a.ctx;
a.resize(), t = new e(a.width, a.height, 6, "#3494E6", "#EC6EAD")
}
return {
run: n
}
}();
if (document.getElementById('lamp-anim')) {
lavaAnimation.run();
}
setTimeout(function() {
$('.js-works-d-list').addClass('is-loaded');
}, 150);
Is it possible to convert/do this in angular animations? Are they flexible enough to do this sort of (what id call advanced) animation?
I think the question of 'can I convert this to Angular' is a bit off because Angular runs on Typescript, which is a language built from javascript. So, yes you can do all this in Angular or rather using Typescript within an Angular app.
We're always here to help once you get some code written in an Angular app! But in general, we are here to help you were you get stuck in code and help you solve the problem. It's a bit more challenging to say 'yes it will work' without seeing how you implement it in your project and can't really guide or help you until we see how your angular components are written.
Short answer: Yeah, I think it can work. But it also depends how you implement this code into your Angular app.

Plot of ND solve differential equation with another parameter

I am trying to solve a differential equation numerically but I need to vary y0 for my plot and view result for constant x. I can solve my equation normally as I expected:but I can't get result when I try for my real purpose as you can see
`\[Sigma] = 1;
n = 23.04;
Rop = y[x];
R = 0.5;
sz = R/(Rop + R);
F = -n*\[Sigma]*y[x]*(1 - 2*sz);
s = NDSolve[{y'[x] == F, y[0] == 0.8}, y, {x, 0, 0.07}]
Plot[Evaluate[y[x] /. s], {x, 0, 0.07}, PlotRange -> All,]`
`[Sigma] = 1;
n = 23.04;
Rop = y[x];
R = 0.5;
sz = R/(Rop + R);
F = -n*\[Sigma]*y[x]*(1 - 2*sz);
y0 = 0.8;
\!\(\*
ButtonBox["Array",
BaseStyle->"Link",
ButtonData->"paclet:ref/Array"]\)[s, 140]
i = 1;
For[i < 140,
s = NDSolve[{y'[x] == F, y[0] == y0}, y, {x, 0, 0.07}]
Plot[Evaluate[y[] /. s], x = 0.07, {y0, 0.8, 2.2}] // print
y0 == y0 + i*0.01];`
A variety of typos or misunderstandings
\[Sigma] = 1;
n = 23.04;
Rop = y[x];
R = 0.5;
sz = R/(Rop + R);
F = -n*\[Sigma]*y[x]*(1 - 2*sz);
y0 = 0.8;
For[i = 1, i < 140, i++,
s = NDSolve[{y'[x] == F, y[0] == y0}, y, {x, 0, 0.07}];
Plot[Evaluate[y[x] /. s], {x, 0, 0.07}] // Print;
y0 = y0 + i*0.01
];
Go through that and compare it a character at a time against your original.
After you have figured out why each of the changes were made then you can try to decide whether to put your Button back in that or not.

Function Plotter error in Dart (with three.dart): Breaking on exception: The null object does not have a method 'crossInto'

The calculations are done in the following code:
var MIN = -10.0,
MAX = 10.0,
RANGE = MAX - MIN;
getColor(max, min, val) {
var MIN_L = 40,
MAX_L = 100;
var color = new Color();
var h = 0 / 240;
var s = 80 / 240;
var l = (((MAX_L - MIN_L) / (max - min)) * val) / 240;
color.setHSL(h, s, l);
return color;
}
initGraph() {
var x = MIN,
y = MIN,
z = 0.0;
initData() {
var data = [];
for (var i = MIN; i < MAX; i++) {
var row = [];
for (var j = MIN; j < MAX; j++) {
double z = 2*( x * x + y * y);
print('$z');
row.add({
x: x,
y: y,
z: z
});
y++;
}
data.add(row);
x++;
}
return data;
}
var data = initData();
var geometry = new Geometry();
var colors = [];
var RANGE = data.length,
height = data[0].length;
data.forEach((col) {
col.forEach((val) {
geometry.vertices.add(new Vector3(x.toDouble(), y.toDouble(), z.toDouble()));
colors.add(getColor(2.5, 0, z.toDouble()));
});
});
offset(x, y) {
return x * RANGE + y;
}
for (var x = 0; x < RANGE - 1; x++) {
for (var y = 0; y < height - 1; y++) {
Vector3 vec0;
Vector3 vec1;
Vector3 n_vec;
// one of two triangle polygons in one rectangle
vec0 = (geometry.vertices[offset(x, y)] - geometry.vertices[offset(x + 1, y)]);
vec1 = (geometry.vertices[offset(x, y)] - geometry.vertices[offset(x, y + 1)]);
n_vec.crossInto(vec0, vec1).normalize();
geometry.faces.add(new Face3(offset(x, y), offset(x + 1, y), offset(x, y + 1), n_vec, [colors[offset(x, y)], colors[offset(x + 1, y)], colors[offset(x, y + 1)]]));
geometry.faces.add(new Face3(offset(x, y), offset(x, y + 1), offset(x + 1, y), n_vec.negate(), [colors[offset(x, y)], colors[offset(x, y + 1)], colors[offset(x + 1, y)]]));
// the other one
vec0 = (geometry.vertices[offset(x + 1, y)] - geometry.vertices[offset(x + 1, y + 1)]);
vec1 = (geometry.vertices[offset(x, y + 1)] - geometry.vertices[offset(x + 1, y + 1)]);
n_vec.crossInto(vec0, vec1).normalize();
geometry.faces.add(new Face3(offset(x + 1, y), offset(x + 1, y + 1), offset(x, y + 1), n_vec, [colors[offset(x + 1, y)], colors[offset(x + 1, y + 1)], colors[offset(x, y + 1)]]));
geometry.faces.add(new Face3(offset(x + 1, y), offset(x, y + 1), offset(x + 1, y + 1), n_vec.negate(), [colors[offset(x + 1, y)], colors[offset(x, y + 1)], colors[offset(x + 1, y + 1)]]));
}
}
var material = new MeshLambertMaterial(vertexColors: VertexColors);
var mesh = new Mesh(geometry, material);
scene.add(mesh);
}
The error seems to be on the occurrence of this line:
n_vec.crossInto(vec0, vec1).normalize();
What is the null object here and how do I solve this? Could the variable 'z' be causing the issue? It first showed null, and caused a similar error (that '*' cannot be applied) and I declared it as double and that got solved. I also have a suspicion in the below lines:
data.forEach((col) {
col.forEach((val) {
geometry.vertices.add(new Vector3(x.toDouble(), y.toDouble(), z.toDouble()));
n_vec is never initialized with an instance of Vector3. crossInto requires to be called on an instance, Either you create an instance first:
Vector3 n_vec = new Vector3.zero();
...
n_vec.crossInto(vec0, vec1).normalize();
Or you use the cross method, but it creates a new instance of Vector3 (you might want to avoid new instances, than I would move the variables out of the loop):
n_vec = vec0.cross(vec1).normalize();

sorting two dimensional array asp classic

So I have a 2d array that I want to Sort. I can sort it easily when one dimensional.
I Hope you can help me guys.
This is my Data.
top5(0,0) = Greeting
top5(0,1) = 2
top5(1,0) = VerifyingInformation
top5(1,1) = 5
top5(2,0) = Calibration
top5(2,1) = 4
I can sort It no problem when one dimensional.
I'm using this code for one dimensional.
For i = LBound(top5) to UBound(top5)
For j = LBound(top5) to UBound(top5) - 1
If top5(j,1) < top5(j + 1,1) Then
TempValue = top5(j + 1,1)
top5(j + 1,1) = top5(j,1)
top5(j,1) = TempValue
End If
next
Next
The result I want to have is this.
VerifyingInformation 5
Calibration 4
Greeting 2
THIS WORKS FOR ME
function sort_arr_mult(byref ArrTmp, ordPlace)
' ordPlace - the place of the order value in the array
' create the new array
Redim arrRet (Ubound(ArrTmp, 1), Ubound(ArrTmp, 2))
for j = 0 to Ubound(ArrTmp, 2)
orderVal = ArrTmp(ordPlace, j)
if j = 0 then ' first enter insert to first column
for i = 0 to Ubound(ArrTmp, 1)
arrRet(i, j) = ArrTmp(i, j)
next
else
' check the first value if smaller or equal
' move the columnbs one field up
' at the end insert to currenct column
for k = 0 to Ubound(arrRet, 2)
if isEmp(arrRet(0, k)) then ' if empty fied the column
for i = 0 to Ubound(arrRet, 1)
arrRet(i, k) = ArrTmp(i, j)
next
exit for
else
if orderVal<=arrRet(ordPlace, k) then
for x = Ubound(arrRet, 2) to k+1 step -1
for i = 0 to Ubound(arrRet, 1)
arrRet(i, x) = arrRet(i, x-1)
next
next
for i = 0 to Ubound(arrRet, 1)
arrRet(i, k) = ArrTmp(i, j)
next
exit for
end if
end if
next ' for k = 0 to Ubound(arrRet, 2)
end if
next
sort_arr_mult = arrRet
end function
It looks like you are actually performing a one-dimensional sort of the numeric value with an associated text string just along for the ride.
Your example code is close but you will need 2 temp values to represent the array values you will be shifting around.
For i = LBound(top5) to UBound(top5)
For j = LBound(top5) to UBound(top5) - 1
If top5(j,1) < top5(j + 1,1) Then
TempValue = top5(j + 1,1)
TempText = top5(j + 1,0)
top5(j + 1,1) = top5(j,1)
top5(j + 1,0) = top5(j,0)
top5(j,1) = TempValue
top5(j,0) = TempText
End If
Next
Next
Extending raam's answer with 3rd parameter as sorting direction "ASC" or "DESC"
Function sortArrayMulti(byref ArrTmp, ordPlace, so)
''so: sortorder "ASC" or "DESC"
Dim j, i, k, orderVal, x
Redim arrRet(Ubound(ArrTmp, 1), Ubound(ArrTmp, 2))
for j = 0 To Ubound(ArrTmp, 2)
orderVal = ArrTmp(ordPlace, j)
if j = 0 Then
for i = 0 to Ubound(ArrTmp, 1)
arrRet(i, j) = ArrTmp(i, j)
next
else
for k = 0 to Ubound(arrRet, 2)
if isEmpty(arrRet(0, k)) then
for i = 0 to Ubound(arrRet, 1)
arrRet(i, k) = ArrTmp(i, j)
next
exit for
else
if so = "ASC" then
if orderVal <= arrRet(ordPlace, k) then
for x = Ubound(arrRet, 2) to k + 1 step -1
for i = 0 to Ubound(arrRet, 1)
arrRet(i, x) = arrRet(i, x - 1)
next
next
for i = 0 to Ubound(arrRet, 1)
arrRet(i, k) = ArrTmp(i, j)
next
exit for
end if
else
if orderVal >= arrRet(ordPlace, k) then
for x = Ubound(arrRet, 2) to k + 1 step -1
for i = Ubound(arrRet, 1) to 0 step -1
arrRet(i, x) = arrRet(i, x - 1)
next
next
for i = 0 to Ubound(arrRet, 1)
arrRet(i, k) = ArrTmp(i, j)
next
exit for
end if
end if
end if
next
end if
next
sortArrayMulti = arrRet
End Function

Resources