I am using Swix to create matrices in Swift. I form my matrix using a list of x values. This was not a problem when my list of x values was a list of integers, but when I try to use decimal numbers in my list of x values I get the error "Cannot subscript a value of type '[Double]'". Here is my code:
@IBAction func button(sender: UIButton) {
let x_values = [3.629, 2, 3]
let y_values:[Double] = [4, 8, 16]
// Counters for loops
var columns = 0
var x_parse = 0
// Create Swix matrix
var mat = eye(x_values.count)
// Assign values to matrix from x_values
while columns < x_values.count {
var rows = x_values.count - 1
var exponent = x_values.count
while rows > -1 {
let element = x_values[x_parse] ^^ exponent
mat[columns, rows] = element
rows = rows - 1
exponent = exponent - 1
}
columns = columns + 1
x_parse = x_parse + 1
}
let y_ndarray = asarray(y_values)
let solution = solve(mat, b: y_ndarray)
print(String(solution))
print(solution)
print(label.text = String(solution))
}
The issue arose in the line:
let element = x_values[x_parse] ^^ exponent
highlighting x_values as the issue.
The code defining the ^^ operator is:
infix operator ^^ { }
func ^^ (radix: Int, power: Int) -> Int {
return Int(pow(Double(radix), Double(power)))
}
How should I access the values in my list if it includes doubles?