Hi I am tying to use the apache commons math lib t...
# getting-started
t
Hi I am tying to use the apache commons math lib to solve systems of linear equations. To this end I have this code
Copy code
var t: Array<Array<Double>> = arrayOf(
        arrayOf(1.0,2.0),
        arrayOf(1.0,2.0),
       arrayOf(1.0,2.0))
        
var n: RealMatrix = MatrixUtils.createRealMatrix(t)
but I get following error
Copy code
e: file:///home/td/NLO3/src/main/kotlin/Function.kt:210:58 Type mismatch: inferred type is Array<Array<Double>> but Array<(out) DoubleArray!>! was expected
changing t's type to
Array<(out) DoubleArray!>!
did not help. Does anyone have an idea how to fix that. If there is an easier solution e.g. maybe an mathlib in Kotlin I am also interested in that Thank you very much for your time
j
When you use the generic
arrayOf
function, it gives you a generic
Array<Double>
. What you want is to use
doubleArrayOf()
so you get a
DoubleArray
(which is different, because it's an array of primitives instead of an array of
Double
object wrappers):
Copy code
var t = arrayOf(
    doubleArrayOf(1.0,2.0),
    doubleArrayOf(1.0,2.0),
    doubleArrayOf(1.0,2.0),
)
👍 2
t
That was fast. Thank you very much