private void startClick(object sender, System.EventArgs e) { step = 1; Apply(); start.Enabled = covariance.Enabled = false; stop.Enabled = true; IAsyncResult result = fit.BeginSolve(null, null); }
private void Demo(object target) { // Fit synchronously using Marquardt algorithm ResetGuess(); MessageBox.Show("Synchronous Marquardt fit algorithm"); // Wait 2 seconds Thread.Sleep(2000); f.Color = Color.Red; // set function color to red plot.Model.Update(f); Fit fit = new Fit(data, f, Fit.FitAlgorithm.Marquardt); fit.StepInterval = 0; // set minimal time interval between Step events to 0, in order to show the progress of the fit. fit.Step += FitStep; fit.Solve(); // Start synchronous Solve f.Color = Color.Black; // fitting finished, set function color back to black plot.Model.Update(f); if (fit.Error) // An exception occured in the fitting algorithm { MessageBox.Show("Error: " + fit.Exception.Message); } // Fit asynchronously using NelderMead algorithm ResetGuess(); MessageBox.Show("Asynchronous Nelder & Mead fit algorithm"); // Wait 2 seconds Thread.Sleep(2000); f.Color = Color.Red; // set function color to red plot.Model.Update(f); fit = new Fit(data, f, Fit.FitAlgorithm.NelderMead); fit.StepInterval = 0; // set minimal time interval between Step events to 0, in order to show the progress of the fit. delay = 75; // set up speed of Nelder & Mead fit faster than Marquardt fit, because Nelder & Mead will invoke the Step event // more often. fit.Step += FitStep; IAsyncResult res = fit.BeginSolve(null, null); // Start asynchronous Solve fit.EndSolve(res); // wait for Solve completion f.Color = Color.Black; // fitting finished, set function color back to black plot.Model.Update(f); if (fit.Error) // An exception occured in the fitting algorithm { MessageBox.Show("Error: " + fit.Exception.Message); } }