在這樣的問題:In F# how can I produce an expression with a type of Func<obj>?,示出了一個單值lambda表達式自動轉換/轉換爲函數功能類型,然後在功能接受。具有多個參數轉換的F#函數的函數功能類型 - MathNet.Numerics
我與MathNet.Numerics庫工作,並可以通過集成確認此X^2介於0和10:
#r "../packages/MathNet.Numerics.3.20.0/lib/net40/MathNet.Numerics.dll"
#r "../packages/MathNet.Numerics.FSharp.3.20.0/lib/net40/MathNet.Numerics.FSharp.dll"
#load "Library1.fs"
open Library3
// Define your library scripting code here
open MathNet.Numerics.Integration
let integral = DoubleExponentialTransformation.Integrate((fun x -> x**2.0), 0.0, 10.0, 1.0)
val answer : float = 333.3333333
但是,我不能讓這個多值函數的工作。當我嘗試這個時,我得到一個類型錯誤。有沒有人知道這個工作?
open MathNet.Numerics.Optimization
open MathNet.Numerics.LinearAlgebra.Double
let newAnswer = BfgsSolver.Solve(DenseVector[|1.0, 1.0|],
(fun x y -> (x + y - 5.0) ** 2.0 + (y - x*x - 4.0) ** 2.0),
(fun x y -> DenseVector[| 2.0 * (x + y - 5.0) - 4.0 * x * (y - x*x - 4);
2.0 * (x + y - 5.0) + 2.0 * (y - x*x - 4.0) |])
)
,我得到以下錯誤...
Script.fsx(20,34): error FS0193: Type constraint mismatch. The type
''a -> 'b -> 'c'
is not compatible with type
'System.Func<MathNet.Numerics.LinearAlgebra.Vector<float>,float>'
嘗試'樂趣(X,Y) - >',而不是'樂趣x和y - >'不是在PC上,將其轉換後回答。 – CaringDev
@CaringDev我有點沮喪地發現,不能正常工作,至少使用'IEnumerable.Aggregate' – TheQuickBrownFox
@TheQuickBrownFox很有可能......沒有做多少F#我的測試 - > C#的互動,不記得確切的情況我遇到了這最後。 – CaringDev