Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #=
- stuff:
- - Julia version: 1.2.0
- - Author: Walter Hafner 3129900, Max Giesel 2837017, Enam Solaimani 3123854
- - Date: 2019-10-23
- =#
- function sorted_exchange(v, in, out)
- println(string("in:" , in, " out: ", out))
- if(findfirst(isequal(out), v) == Nothing())
- return "no such element"
- end
- if(!issorted(v))
- return "given vector must be sorted"
- end
- i = searchsortedfirst(v, out)
- v[i] = in
- sort!(v, alg = InsertionSort)
- return v
- end
- println("Aufgabe 4.1")
- arr = [1, 2, 4, 5, 6, 7, 7, 11, 15, 15 , 16]
- println(string("sorted_exchange($arr) = ",sorted_exchange(arr, 8, 7)))
- println(string("sorted_exchange($arr) = ",sorted_exchange(arr, 0, 16)))
- println(string("sorted_exchange($arr) = ",sorted_exchange(arr, 3, 4)))
- function det(A)
- d = A[1] * A[5] * A[9] + A[2] * A[6] * A[7] + A[3] * A[4] * A[8]
- d -= A[7] * A[5] * A[3]
- d -= A[8] * A[6] * A[1]
- d -= A[9] * A[4] * A[2]
- return d
- end
- println("\r\nAufgabe 4.2")
- arr = [1 11 3; 4 5 6; 7 8 9]
- println(string("det($arr) = ",det(arr)))
- arr = [1 11 3; 44 5 6; 7 8 9]
- println(string("det($arr) = ",det(arr)))
- arr = [1 12 3; 4 5 6; 7 88 9]
- println(string("det($arr) = ",det(arr)))
- function tosparse(A)
- n = size(A, 1)
- m = size(A, 2)
- println(string("--tosparse() einer ",n , "x", m, "-matrix--"))
- #println(m)
- pOuter = Dict{Array{Int64,2}, Int64}()
- #println(string("das ist ", pOuter))
- for i=1:n
- for j=1:m
- if(!isequal(A[i, j],0))
- pOuter[[i j]] = A[i, j]
- end
- end
- end
- return pOuter
- end
- println("\r\nAufgabe 4.3")
- arr = [1 12 0; 4 0 6; 7 0 9; 7 0 0]
- println(string("mit $arr:\r\n",tosparse(arr)))
- arr = [9 1 0; 0 0 6; 7 0 9; 7 0 0; 0 0 1]
- println(string("mit $arr:\r\n",tosparse(arr)))
- arr = [9 0 1 0; 1 0 0 6; 0 7 0 9; 0 7 0 0; 8 0 0 1]
- println(string("mit $arr:\r\n",tosparse(arr)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement