#r "nuget: MathNet.Numerics"
#r "nuget: MathNet.Numerics.FSharp"
#r "nuget: Plotly.NET, 2.0.0"
#r "nuget: Plotly.NET.Interactive, 2.0.0"
open Plotly.NET
open MathNet.Numerics
open MathNet.Numerics.LinearAlgebra
let matrix1 = matrix [[1.0; 2.0]; [5.0; 6.0]]
let matrix2 = matrix [[3.0; 3.0]; [7.0; 8.0]]
let matrix12 = matrix1 * matrix2
let myFirstChart = Chart.Point(matrix12) //TYPE CAST ERROR
let myFirstStyledChart =
Chart.Point(xData,yData)
|> Chart.withTitle "Hello world!"
|> Chart.withXAxisStyle ("xAxis")
|> Chart.withYAxisStyle ("yAxis")
|> Chart.show
我得到错误
Error: input.fsx (9,32)-(9,40) typecheck error The type 'Matrix<float>' is not compatible with the type 'seq<'a * 'b>'
input.fsx (9,32)-(9,40) typecheck error Type constraint mismatch. The type
'Matrix<float>'
is not compatible with type
'seq<'a * 'b>'
是否有一种紧凑的方法可以从Matrix到seq<>在f#中不需要很大的转换函数。我只是在寻找一种快速的方法来显示向量和矩阵。
它不需要是一个复杂的函数,但你需要一些方法将矩阵转换成你的图上的x和y数据。例如:
let x = matrix12.ToArray()
let plottable =
seq {
for i in 0..(Array2D.length1 x - 1) do
for j in 0..(Array2D.length2 x - 1) do
yield (i * j), x.[i, j]
}
let myFirstChart = Chart.Point(plottable)