Is that possible to Implement ๐ฟ๐ factorization without row pivoting ? can someone give me an example?
lu(A,Val(false))
I donโt want to use LinearAlgebra package , I want to implement the algorithm from scratch
Well, you can look at the source code for the Pivot == false
case. But if this is a learning exercise (or a homework problem), you might want to try to implement it yourself from a textbook description.
Than you .Can you tell me the name of textbook that can describe how to implement this code ?
If this really is a homework assignment, you should do some of the work yourself. As for LA resources, check out e.g. http://ulaff.net/.
I tried it like that :
using LinearAlgebra
using SparseArrays
function LU2(A::Union{Array{real},Array{Float64}})
n = size(A,1); # Assuming A is nxn.
U = copy(A);
L = eye(eltype(A),n);
for k=2:n
for i=k:n
L[i,k-1] = U[i,k-1]/U[k-1,k-1];
for j=k-1:n
U[i,j] = U[i,j] - L[i,k-1]*U[k-1,j];
end
end
end
return L,U
end
but the problem now is when I test it i got this error ( UndefVarError: eye not defined)
You can get the n \times n identity matrix using Matrix{eltype(A)}(I,(n,n))
.
I got UndefVarError: eltpe not defined
Sorry, typo. Fixed now.
thanks it works
Deleted code
You probably want abs.(array)
.
I did it like this
pivot = indmax(abs.(U[(k-1):n,k-1])) + k - 2;
but i got UndefVarError: indmax not defined
The function that used to be called.indmax
is now called findmax
.
Thanks.it works but i got different error
MethodError: no method matching +(::Tuple{Float64,Int64}, ::Int64)
Did you try running the findmax
function to see what kind of object it returns? And you can read the documentation of the function using ?findmax
from the REPL.
Ah thereโs also argmax
.
Yes i did. it works but when I test it on a matrix I got this strange error
( MethodError: no method matching +(::Tuple{Float64,Int64}, ::Int64) )
I tried to figure out the problem in the code again but i didnโt note whatโs the problem
findmax
returns a tuple.
It is telling you that you are trying to add that tuple to an integer.