public void Test_ExpansionWorks() { var algorithm = new GoldenSectionMinimizer(1e-5, 1000); var f1 = new Func <double, double>(x => (x - 3) * (x - 3)); var obj = new SimpleObjectiveFunction1D(f1); var r1 = algorithm.FindMinimum(obj, -5, 5); Assert.That(Math.Abs(r1.MinimizingPoint - 3.0), Is.LessThan(1e-4)); }
private MTPA buildTableMaxtorquePerAmple() { string config = string.Format("{0},{1},{2},{3},{4}", R, p, Ld, Lq, psiM); if (_param_config == config) { return(_mtpa); } int stepcount = 100; //int beta_count = 90; var idqs = new List <Fdq>(); var max_torques = new List <double>(); int k = 0; for (int i = 0; i < stepcount + 1; i++) { double II = 1000 * i / stepcount; var minimizer = new GoldenSectionMinimizer(); var objfnc = new SimpleObjectiveFunction1D(beta_rad => { double id = II * Math.Cos(beta_rad); double iq = II * Math.Sin(beta_rad); var data = calculatePointdata(id, iq, 3000); k++; return(-data.torque); }); var min = minimizer.FindMinimum(objfnc, Math.PI / 2, Math.PI); if (min != null) { double beta_rad = min.MinimizingPoint; double max_t = -min.FunctionInfoAtMinimum.Value; max_torques.Add(max_t); idqs.Add(new Fdq { d = II * Math.Cos(beta_rad), q = II * Math.Sin(beta_rad), }); } } Console.WriteLine("Call calc count = " + k); MTPA mtpa = new MTPA() { idqs = idqs, max_torques = max_torques }; _mtpa = mtpa; _param_config = config; return(mtpa); }