I'm having trouble creating this matrix in Julia. I need to find the LU factorization, which I believe I know the code for. Should I be choosing my own $n$ here?

enter image description here


closed as off-topic by Namaste, Did, user99914, Guy Fsone, Saad Apr 3 '18 at 4:29

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question is missing context or other details: Please improve the question by providing additional context, which ideally includes your thoughts on the problem and any attempts you have made to solve it. This information helps others identify where you have difficulties and helps them write answers appropriate to your experience level." – Namaste, Did, Community, Guy Fsone, Saad
If this question can be reworded to fit the rules in the help center, please edit the question.


To construct $A$, you declare $a = (a_1, \dots, a_n)$, $b = (b_1, \dots, b_{n-1})$ and $c = (c_1, \dots, c_{n-1})$. The length of the diagonal $n$ will be determined by that of the vector $a$, so there's no need to manually declare the value of $n$.

# Declare vectors a, b and c
A = diagm(a) + diagm(b, -1) + diagm(c, 1)  # Create matrix A
Alu = lufact(A)                            # Compute PA = LU and store result as Alu
typeof(Alu)                                # return : Base.LinAlg.LU{Float64,Array{Float64,2}}
Alu[:P]                                    # Extract permutation matrix P
Alu[:L]                                    # Extract lower triangular unit diagonal matrix L
Alu[:U]                                    # Extract upper triangular matrix U
  • $\begingroup$ @c87 From the picture, I suppose that the $a_i$'s are given. The first line in the code block reads "declare a, b and c", so you need to do that before you construct $A$. To do so, use a = [a_1 a_2 ... a_n]. For example, a = [1 2 3 ... n]. $\endgroup$ – GNUSupporter 8964民主女神 地下教會 Mar 29 '18 at 22:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.