Just to finish the job, I've had a go at baksub.
Here my efforts for both forward and backward substitution:
All 4 examples require the vector and matrix arguments to
have the same length.
NB. successively append new elements to new vector z
forsuba=: 4 : 0
a =. x%d=.x|:~<0 1
b =. y%d
z =. ''
f
On Wed, Sep 2, 2015 at 3:17 PM, Mike Day wrote:
> nicely concise. I feel there's a closed form hiding in there
> somewhere, to replace the explicit loop, but haven't found
> it yet!
baksub looks like it could be done using u/\. but forsub would have to
be some sort of u/&|.\ expression.
--
Ra
I've had a look at forsub this afternoon. I've cribbed Raul's
pre-factoring by
the matrix-diagonal, but otherwise they're my own ideas. Nothing out of
the ordinary, but fairly concise. "J-like"? - perhaps.
NB. these both assume that #x = #y
NB. Thunderbird will probably spoil the appeara
On Tue, Sep 1, 2015 at 11:42 PM, Thomas McGuire wrote:
> Thanks I will try out your changes. Though in my implementation I was trying
> to avoid multiplying the zero entries and your routines ignore that.
Yep. It's slower to toss them than it is to just ignore them.
Reason being that you're mak
Thanks I will try out your changes. Though in my implementation I was trying to
avoid multiplying the zero entries and your routines ignore that:
> z1=. (i{b) - (i{a) +/ .* z
Here multiplying by all elements of a row and letting the zeros get rid of the
unnecessary data in z in that particular
I'm not sure I'd get rid of the for loop.
That said, here's a rephrase to make it more "j-like":
forsub=: 4 :0
d=. (<0 1)|:x
a=. x%d
b=. y%d
z=. (#b){.{.b
for_i.}.i.#b do.
z1=. (i{b) - (i{a) +/ .* z
z=. z1 i} z
end.
)
NB. Back substitution - multiply lower triangular matrix b
Sorry I should have rerun the stuff rather than just pick through my debugging
session.
The original Matrix
]A1 =: 3 3$1 2 3 2 _4 6 3 _9 _3
1 2 3
2 _4 6
3 _9 _3
LU decomposition triangular matrix L1 and U1 are
L1
1 0 0
2 _8 0
3 _15 _12
U1
1 2 3
0 1 0
0 0 1
b1 =: 5 18 6 NB. this i
Can you double check whether you have posted what you intended?
I get
b1 %. A1
4.15625 1.375 _0.635417
L1 forsub b1
5 1.375 _0.635417
U1 baksub L1 forsub b1
0.517014 0.941667 _0.0635417
which does not correspond to the result you displayed.
Thanks,
--
Raul
On Mon, Aug 31, 2015 at 9:5
I have been playing around with creating forward substitution and backward
substitution J scripts to solve lower and upper triangular matrices of the type
you would get by performing LU decomposition on a single square matrix. I could
certainly just use matrix divide but this starts to slow down