/// <summary> /// Returns a deep copy. /// </summary> public override PlotItem Clone() { Function1D item = new Function1D(); item.CopyFrom(this); return(item); }
/// <summary> /// Returns a deep copy. /// </summary> public override PlotItem Clone() { Function1D item = new Function1D(); item.CopyFrom(this); return item; }
public void ResetPar() { bool fitpok = true; lock(this) { GraphModel model = graph.Model; string name; int i; name = (string)function.Text; f = null; for (i = 0; i < model.Items.Count; i++) { if ((model.Items[i].name == name) && (model.Items[i] is Function1D) && (((Function1D)model.Items[i]).Fitable())) { f = (Function1D)model.Items[i]; } } name = (string)data.Text; dataItem = null; for (i = 0; i < model.Items.Count; i++) { if ((model.Items[i].name == name) && (model.Items[i] is DataItem)) { dataItem = (DataItem)model.Items[i]; } } if (f != null) { if (f != oldf || f.Modified) { if (f != oldf) { fitp = new bool[f.p.Length]; for (i = 0; i < f.p.Length; i++) { fitp[i] = true; } } grid.ColumnsCount = 4; grid.RowsCount = f.p.Length + 1; grid[0, 0] = new SourceGrid2.Cells.Real.ColumnHeader("n"); grid[0, 1] = new SourceGrid2.Cells.Real.ColumnHeader("fit"); grid[0, 2] = new SourceGrid2.Cells.Real.ColumnHeader("p[n]"); grid[0, 3] = new SourceGrid2.Cells.Real.ColumnHeader("±Δp[n]"); for (i = 0; i < f.p.Length; i++) { grid[i+1, 0] = new SourceGrid2.Cells.Real.RowHeader(i.ToString()); grid[i+1, 1] = new SourceGrid2.Cells.Real.CheckBox(fitp[i]); grid[i+1, 2] = new SourceGrid2.Cells.Real.Cell(f.p[i], typeof(double)); if (covar == null) { grid[i+1, 3] = new SourceGrid2.Cells.Real.Cell("", typeof(string)); } else { grid[i+1, 3] = new SourceGrid2.Cells.Real.Cell(Math.Sqrt(covar[i, i]), typeof(double)); } grid[i+1, 3].DataModel.EnableEdit = false; } covar = null; } plength = f.p.Length; } if (f == null) { grid.RowsCount = 4; grid.ColumnsCount = 1; grid[0, 0] = new SourceGrid2.Cells.Real.ColumnHeader("n"); grid[0, 1] = new SourceGrid2.Cells.Real.ColumnHeader("fit"); grid[0, 2] = new SourceGrid2.Cells.Real.ColumnHeader("p[n]"); grid[0, 3] = new SourceGrid2.Cells.Real.ColumnHeader("±Δp[n]"); } grid.AutoSize(); oldf = f; Q.Text = ""; chisq.Text = ""; covariance.Enabled = covar != null; fitpok = false; for (i = 0; i < fitp.Length; i++) { if (fitp[i]) fitpok = true; } start.Enabled = (f != null && data != null && fitpok); neval.Text = ""; } }
private void cosClick(object sender, System.EventArgs e) { Function1D cos = new Function1D(); cos.source = "return cos(x);"; cos.Compile(true); cos.Color = Color.Red; cos.lineWidth = 2; cos.lineStyle = DashStyle.Dash; graph.Model.Items.Add(cos); graph.Invalidate(); }
private void gaussClick(object sender, System.EventArgs e) { Function1D gauss = new Function1D(); //Here the source accesses the array p, an array of function parameters. //When you compile the item, the size of p is automatically set to the //highest element referred to in the source. gauss.source = "double arg = (x-p[0])/p[1]; return p[2]*exp(-arg*arg);"; gauss.Compile(true); gauss.p[0] = 1; gauss.p[1] = 1; gauss.p[2] = 4; graph.Model.Items.Add(gauss); graph.Invalidate(); }
private void stopamo(float[] pb) { int i, j; covar = new float[0, 0]; float[,] alpha = new float[0, 0]; float alamda; chisq = 0; f = new DerivFunction(f0); if (f is DerivFunction) ((DerivFunction)f).fast = false; for (i = 0, j = 0; i < f.p.Length; i++) { if (ip0[i]) f.p[i] = pb[j++]; } alamda = -1; mrqmin(ip0, ref covar, ref alpha, ref chisq, ref alamda); alamda = 0; mrqmin(ip0, ref covar, ref alpha, ref chisq, ref alamda); ip0 = null; p0 = null; ptry = null; }
private void sinClick(object sender, System.EventArgs e) { Function1D sin = new Function1D(); //The source represents the body of the following function: //double[] p, dfdp; //double f(double x) { // ... //} sin.source = "return sin(x);"; sin.Compile(true); sin.Color = Color.Blue; sin.lineWidth = 2; graph.Model.Items.Add(sin); graph.Invalidate(); }
public Fit(DataItem data, Function1D f, bool[] fitp) { Data = data; f0 = f; this.fitp = (bool[])fitp.Clone(); }
private void NelderMeadStart(bool T0) { const int TFAC = 3; chisq = 0; f = f0; if (T0) T = 0; else T = data.Length*TFAC; NEval = 0; ThreadPool.QueueUserWorkItem(new WaitCallback(NelderMeadThread)); //Do(); }
public Fit(DataItem data, Function1D f) { Data = data; Function = f; }
private void MarquardtStart() { chisq = 0; oldchisq = -1e10F; alamda = -1; NEval = 0; if (f0.p.Length > 0 && f0.dfdp.Length == 0) { f = new DerivFunction(f0); } else f = f0; ThreadPool.QueueUserWorkItem(new WaitCallback(MarquardtThread)); //Do(); }
public DerivFunction(Function1D f) { code = f.code; p = f.p; if (f.dfdp.Length == f.p.Length) { dfdp = f.dfdp; fast = true; this.f = f.f; } else { dfdp = new SmallData(); fast = true; dfdp.Length = p.Length; this.f = new Code(F); } }