Thursday, October 24, 2019

Scala: combining two different maps with a common key

Friday, October 18, 2019

Cholesky Decomposition Matrix and Example - Numerical Methods

https://www.youtube.com/watch?v=j1epLYdfqT4

https://en.wikipedia.org/wiki/Triangular_matrix

In this video I use Cholesy decomposition to find the lower triangular matrix and its transpose! ITS SIMPLE! STEP 1 Set your given matrix equal to the product of a lower triangular matrix and its transpose and use constants to fill in the slots - make sure the diagonals of the lower triangular matrix equal that of its transpose! STEP 2 perform matrix multiplication and develop your matrix filled with constants. STEP 3 set the matrix you just developed equal to the given matrix. It is the same size matrix so set each component of your developed matrix equal to that of the given matrix and solve for each component one at a time. STEP 4 EAT GLUTEN AND PROSPER XD check out the following link for the Crout's method: https://www.youtube.com/watch?v=yYxwl... and for Doolittle Method: https://www.youtube.com/watch?v=jbeX2...

More Scala case classes converted to nested tuples converted to nested maps

   case class X(a: String, b: String, c: String, d: String )
  val x = Seq(X("a", "b", "c", "d"), X("a", "b", "p", "q") )
  x.map{case X(a,b,c,d) => (a -> (b -> (c, d)))}.groupBy(_._1)
  x.map{case X(a,b,c,d) => (a -> (b -> (c, d)))}.groupBy(_._1).map{case (k,v) => (k -> v.map(_._2))}
  x.map{case X(a,b,c,d) => (a -> (b -> (c, d)))}.groupBy(_._1).map{case (k,v) => (k -> v.map(_._2).groupBy(_._1).map{case (k,v) => (k -> v.map(_._2))})}
x.map{case X(a,b,c,d) => (a -> (b -> (c, d)))}.groupBy(_._1).map{case (k,v) => (k -> v.map(_._2).groupBy(_._1).map{case (k,v) => (k -> v.map(_._2).groupBy(_._1).flatMap(_._2))})}



scala>  case class X(a: String, b: String, c: String, d: String )
defined class X
scala>         val x = Seq(X("a", "b", "c", "d"), X("a", "b", "p", "q") )
x: Seq[X] = List(X(a,b,c,d), X(a,b,p,q))
scala>         x.map{case X(a,b,c,d) => (a -> (b -> (c, d)))}.groupBy(_._1)
res140: scala.collection.immutable.Map[String,Seq[(String, (String, (String, String)))]] = Map(a -> List((a,(b,(c,d))), (a,(b,(p,q)))))
scala>         x.map{case X(a,b,c,d) => (a -> (b -> (c, d)))}.groupBy(_._1).map{case (k,v) => (k -> v.map(_._2))}
res141: scala.collection.immutable.Map[String,Seq[(String, (String, String))]] = Map(a -> List((b,(c,d)), (b,(p,q))))
scala>         x.map{case X(a,b,c,d) => (a -> (b -> (c, d)))}.groupBy(_._1).map{case (k,v) => (k -> v.map(_._2).groupBy(_._1).map{case (k,v) => (k -> v.map(_._2))})}
res142: scala.collection.immutable.Map[String,scala.collection.immutable.Map[String,Seq[(String, String)]]] = Map(a -> Map(b -> List((c,d), (p,q))))
scala>       x.map{case X(a,b,c,d) => (a -> (b -> (c, d)))}.groupBy(_._1).map{case (k,v) => (k -> v.map(_._2).groupBy(_._1).map{case (k,v) => (k -> v.map(_._2).groupBy(_._1).flatMap(_._2))})}
res143: scala.collection.immutable.Map[String,scala.collection.immutable.Map[String,scala.collection.immutable.Map[String,String]]] = Map(a -> Map(b -> Map(p -> q, c -> d)))