Created
January 9, 2010 13:06
-
-
Save AndreaCrotti/272883 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) * y1 | |
endif | |
if alg == 2 | |
L21 = Lbr(1:b, b+1:columns(Lbr)) | |
y2 = yb(b+1:length(yb)) | |
x(1) = inverse(L11) * 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