Advertisement
wambologie

enam

Nov 4th, 2019
1,617
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 1.91 KB | None | 0 0
  1. #=
  2. stuff:
  3. - Julia version: 1.2.0
  4. - Author: Walter Hafner 3129900, Max Giesel 2837017, Enam Solaimani 3123854
  5. - Date: 2019-10-23
  6. =#
  7. function sorted_exchange(v, in, out)
  8.     println(string("in:" , in, " out: ", out))
  9.     if(findfirst(isequal(out), v) == Nothing())
  10.         return "no such element"
  11.     end
  12.     if(!issorted(v))
  13.         return "given vector must be sorted"
  14.     end
  15.     i = searchsortedfirst(v, out)
  16.     v[i] = in
  17.     sort!(v, alg = InsertionSort)
  18.  
  19.  
  20.     return v
  21. end
  22.  
  23. println("Aufgabe 4.1")
  24. arr = [1, 2, 4, 5, 6, 7, 7, 11, 15, 15 , 16]
  25. println(string("sorted_exchange($arr) = ",sorted_exchange(arr, 8, 7)))
  26. println(string("sorted_exchange($arr) = ",sorted_exchange(arr, 0, 16)))
  27. println(string("sorted_exchange($arr) = ",sorted_exchange(arr, 3, 4)))
  28.  
  29. function det(A)
  30.     d = A[1] * A[5] * A[9] + A[2] * A[6] * A[7] + A[3] * A[4] * A[8]
  31.     d -= A[7] * A[5] * A[3]
  32.     d -= A[8] * A[6] * A[1]
  33.     d -= A[9] * A[4] * A[2]
  34.     return d
  35. end
  36.  
  37. println("\r\nAufgabe 4.2")
  38. arr = [1 11 3; 4 5 6; 7 8 9]
  39. println(string("det($arr) = ",det(arr)))
  40. arr = [1 11 3; 44 5 6; 7 8 9]
  41. println(string("det($arr) = ",det(arr)))
  42. arr = [1 12 3; 4 5 6; 7 88 9]
  43. println(string("det($arr) = ",det(arr)))
  44.  
  45. function tosparse(A)
  46.     n = size(A, 1)
  47.     m = size(A, 2)
  48.  
  49.     println(string("--tosparse() einer ",n , "x", m, "-matrix--"))
  50.     #println(m)
  51.     pOuter = Dict{Array{Int64,2}, Int64}()
  52.     #println(string("das ist ", pOuter))
  53.     for i=1:n
  54.         for j=1:m
  55.             if(!isequal(A[i, j],0))
  56.                 pOuter[[i j]] = A[i, j]
  57.             end
  58.         end
  59.     end
  60.     return pOuter
  61. end
  62.  
  63. println("\r\nAufgabe 4.3")
  64. arr = [1 12 0; 4 0 6; 7 0 9; 7 0 0]
  65. println(string("mit $arr:\r\n",tosparse(arr)))
  66. arr = [9 1 0; 0 0 6; 7 0 9; 7 0 0; 0 0 1]
  67. println(string("mit $arr:\r\n",tosparse(arr)))
  68. arr = [9 0 1 0; 1 0 0 6; 0 7 0 9; 0 7 0 0; 8 0 0 1]
  69. println(string("mit $arr:\r\n",tosparse(arr)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement