在这样的问题: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