Skip to content

Instantly share code, notes, and snippets.

@AndreaCrotti
Created January 9, 2010 12:57
Show Gist options
  • Save AndreaCrotti/272880 to your computer and use it in GitHub Desktop.
Save AndreaCrotti/272880 to your computer and use it in GitHub Desktop.
function x = trsv(L, y, b, alg)
len = length(L);
req = len / b;
## this could be whatever, after I overwrite any value present
x = 1:len
## the condition on size(Ltl) is automatically fulfilled here
for idx = 0:req
step = idx
s = idx * b;
## avoiding overflow when b > 1
if s > len
s = len
endif
Ltl = L(1:s, 1:s)
Lbl = L(s+1:len, 1:s)
Lbr = L(s+1:len, s+1:len)
if (length(Ltl) == len)
return
endif
## but where do I instantiate x?
xt = x(1:s)
xb = x(s+1:len)
yt = y(1:s)
yb = y(s+1:len)
## setting variables needed for both algorithms
L11 = Lbr(1:b, 1:b)
x1 = xb(1:b)
y1 = yb(1:b)
v = vec(y1)
## math part, choosing which algorithm to execute
if alg == 1
L10 = Lbl(1:b, 1:columns(Lbl))
y0 = yt
y(1) = y1 - L10 * y0
x(1) = inverse(L11) * vec(y1)
endif
if alg == 2
L21 = Lbr(1:b, b+1:columns(Lbr))
y2 = yb(b+1:length(yb))
x(1) = inverse(L11) * vec(y1)
y(2) = y2 - L21 * x1
endif
endfor
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment