如果我是对的,那么ilnumerics中就有一个优化工具箱。在我的项目中成功安装ilnumerics后,我尝试在其中编写http://ilnumerics.net/media/ILNumericsOptimizationToolboxDocumentation.pdf的一些示例。但是,无论何时我使用 * =优化。* 都会出现错误,例如“优化”是一个未完成的变量。 “当前上下文中不存在'优化'这个名称”
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ILNumerics;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
class Program : ILMath
{
public static ILRetArray<double> MeyerFunc(ILInArray<double> x, ILInArray<double> t)
{
using (ILScope.Enter(x, t))
{
return x[0] * exp(x[1] / (t + x[2]));
}
}
//The computation of the minimum is done as follows:
// Minimum computation:
ILArray<double> t = linspace<double>(0, 15, 16).T;
ILArray<double> ydata = array<double>(34780.0, 28610.0, 23650.0, 19630.0, 16370.0,
13720.0, 11540.0, 9744.0, 8261.0, 7030.0,
6005.0, 5147.0, 4427.0, 3820.0, 3307.0, 2872.0);
ILArray<double> x0 = array<double>(1.0, 200.0, 100.0);
Func<ILInArray<double>, ILRetArray<double>> meyerfunction = x =>
{
using (ILScope.Enter(x))
{
return MeyerFunc(x, t);
}
};
ILArray<double> xm = Optimization.optimpdl(meyerfunction, x0, ydata);
}
}
答案 0 :(得分:0)
该行
ILArray<double> xopt = Optimization.optimpdl(objfunc, zeros<double>(2, 1));
应该在main函数内部,而不是在它之外和之外。