

matrix // overwrite a sub-matrix with the content of another matrix: m. init 6 4 ( fun i j -> float ( 10 * i + j ) ) m. In F# we can also use its slicing syntax: let m = DenseMatrix. To overwrite those elements with the provided data. M.SubMatrix( 1, 2, 1, 2) // įor each of these methods there is also a variant prefixed with Set that can be used We can also get entire column or row vectors, or a new matrix from parts of an existing one.
PRINCIPAL UNIT NORMAL VECTOR 2D CODE
For example, an in-place version of the code above: m.Multiply(v, v) // v. Provided theĭimensions match, most also allow one of the arguments to be passed as result, These methods also have an overload that accepts the result data structure as last argument,Īllowing to avoid allocating new structures for every single operation. The equivalent code fromĪbove when using instance methods: var v 2 = m.Multiply(v) anspose.īut even the operators have equivalent methods. Or in F# as functions in the Matrix module, e.g. let m = matrix ] let v = vector let v' = m * v let m' = m + 2.0 * m Arithmetic Instance MethodsĪll other operations are covered by methods, like Transpose and Conjugate, ArithmeticsĪll the common arithmetic operators like +, -, *, / and % are provided,īetween matrices, vectors and scalars. Or using any other of all the available functions. random 3 4 ( ContinuousUniform ( - 2.0, 4.0 ) ) let m7b = DenseMatrix. randomStandard 3 4 // random matrix with a uniform and one with a Gamma distribution: let m7a = DenseMatrix. ofColumnSeq x // random matrix with standard distribution: let m6 = DenseMatrix. init 3 ( fun r -> float ( 100 * r + c ) ) ) let m5 = DenseMatrix. identity 4 // dense 3x4 matrix created from a sequence of sequence-columns let x = Seq. init 3 4 ( fun i j -> float ( i + j ) ) // diagonal 4x4 identity matrix of single precision let m4 = DiagonalMatrix. zero 3 4 // dense 3x4 matrix initialized by a function let m3 = DenseMatrix. (usually the type is inferred, but not for zero matrices) let m2 = DenseMatrix. In F# we can use the builders just like in C#, but we can also use the F# modules: let m1 = matrix ] let v1 = vector // dense 3x4 matrix filled with zeros. Directly bind to an existing array without copying (note: no "Of") double x = existing. They support both single and double precision, real and complex floating point numbers.Ī_ That would show that they are orthogonal and unit Numerics includes rich types for matrices and vectors. NOTE: If you continue to normalize the original provided vector to get #hatu = >#, you can show that #hatu xx hatv = hatw#, #hatv xx hatw = hatu#, #hatw xx hatu = hatv#, and so on, just like the unit vectors #hati,hatj,hatk#. So, the two unit vectors orthogonal to #># are: The two vectors we found were not unit vectors though, and are just vectors. Let us set them on the #xy#-plane so that our vectors are: Then, the two vectors we evaluated before must be projected onto three dimensions. Where we use the identities #hatixxhatj = hatk# and #hatixxhatj = -hatjxxhati#. #= -12cancel(hatixxhati)^(0) - 9hatixxhatj + 16hatjxxhati + 12cancel(hatjxxhatj)^(0)# Try converting the vectors to a sum of unit vectors #hati# and #hatj# multiplied by coefficients: The second vector orthogonal to these can be found from taking the cross product of the two vectors we now have. You can also check by drawing out the actual vector on the xy-plane. #hatR = #Īnd you can see that they are orthogonal by checking the dot product: One way to generate the first vector orthogonal to #># is to use a rotation matrix to rotate the original vector by a clockwise rotation of #theta# degrees: Orthogonal means from another vector, and unit vectors have a length of #1#. Try drawing these out and see if you can see where I'm getting this.

Note that we could have also used any of the following pairs: Assuming that the vectors all have to be orthogonal to each other (so the two vectors we found are orthogonal to each other as well).
