コード例 #1
0
 public FunctionLineStyleForm(MainModel m, Function1DItem f)
 {
     InitializeComponent();
     Model = m;
     lineStyle.Reset();
     Reset(f);
 }
コード例 #2
0
 public void Reset(Function1DItem f)
 {
     this.f = f;
     lineStyle.SelectedStyle = f.LineStyle;
     this.width.Text         = f.LineWidth.ToString();
     this.color.BackColor    = f.Color;
     this.Text = f.Name + " - " + Properties.Resources.LineStyle;
 }
コード例 #3
0
ファイル: FitDemo.cs プロジェクト: lulzzz/JohnshopesFPlot
        public FitDemo(PlotControl plot)
        {
            this.plot = plot;

            plot.Model.Clear();

            // create a new DataItem
            data = new DataItem();

            data.Dimensions   = 2;              // This property is only used by the LoadText method, it is not required for the fit algorithm.
            data.ErrorColumns = true;           // This property is only used by the LoadText method, it is not required for the fit algorithm.

            // preset the x, dx and dy values to functions:
            data.x.Source  = "n/Length*12 - 8"; // place the data in the visible plot range (x0: -8; x1: 4 in this demo application)
            data.dx.Source = "0.5";             // set the x errors to 0.5 (the x errors are not used by the fit algorithm)
            data.dy.Source = "y[n]*0.2";        // set y errors to 20% of the x values
            data.Compile();

            data.LoadText("Gauss data.txt", "\n");             // Load the data from the "Gauss data.txt" text file.

            // Display data
            plot.Model.Add(data);

            // create a new function
            f = new Function1DItem(@"
				// M - gauss curves with derivative information in dfdp.
				const int M = 3;
				double arg, ex, fac, sum = 0;
				for (int n = 0; n < 3*M; n += 3) {
					arg = (x - p[n + 1])/p[n + 2];
					ex = Math.Exp(-arg*arg);
					fac = p[n]*ex*2*arg;

					// Compute derivative information in order to speed up the Marquardt fitting algorithm. Marquardt also works with no
					// derivative information provided by the funciton, so you can also omit this, it then computes numerical derivatives.
					// The NelderMead fitting algorithm uses no derivatives.
					dfdp[n] = ex;
					dfdp[n + 1] = fac/p[n + 2];
					dfdp[n + 2] = fac*arg/p[n + 2];

					// compute the sum over all gauss curves.
					sum += p[n]*ex;
				}
				return sum;
			"            );
            f.Compile();

            // Set initial fit guess.

            ResetGuess();

            // Display function
            plot.Model.Add(f);
        }
コード例 #4
0
 public void Reset()
 {
     if (oldItem == null)
     {
         dimensions   = Dimensions.One;
         fSource.Text = "return 0;";
     }
     else
     {
         if (oldItem is Function1DItem)
         {
             SetDimensions(Dimensions.One);
         }
         else if (oldItem is Function2DItem)
         {
             SetDimensions(Dimensions.Two);
         }
         else if (oldItem is FunctionColorItem)
         {
             SetDimensions(Dimensions.TwoColor);
         }
         else
         {
             throw new System.ApplicationException("invalid item-type");
         }
         name.Text = oldItem.Name;
         this.Text = oldItem.Name;
         if (oldItem is Function1DItem)
         {
             Function1DItem f1 = (Function1DItem)oldItem;
             fSource.Text    = f1.Source;
             style.Color     = f1.Color;
             style.LineWidth = f1.LineWidth;
             style.LineStyle = f1.LineStyle;
         }
         else if (oldItem is Function2DItem)
         {
             Function2DItem f1 = (Function2DItem)oldItem;
             fSource.Text = f1.Source;
             Gradient     = f1.Gradient;
         }
         else if (oldItem is FunctionColorItem)
         {
             FunctionColorItem f1 = (FunctionColorItem)oldItem;
             fSource.Text = f1.Source;
         }
     }
 }
コード例 #5
0
 protected void FunctionChanged(object sender, EventArgs e)
 {
     plot.Model.Clear();                      // The state of the plot is saved across page requests, so we need to clear the Model.
     plot.Model.SetRange(-10, 10, -1.1, 1.1); // set the plotting range for plot
     if (list.SelectedValue == "Sine")
     {
         Function1DItem sin = new Function1DItem("return sin(x);");
         plot.Model.Add(sin);
     }
     else if (list.SelectedValue == "Cosine")
     {
         Function1DItem cos = new Function1DItem("return cos(x);");
         plot.Model.Add(cos);
     }
     plot.Model.y.fix = true;         // disable zooming in the y scale.
 }
コード例 #6
0
        public static void Gauss(PlotControl plot)
        {
            // Here we create a new Function1DItem, directly setting and compiling
            // its source throught the constructor.
            Function1DItem gauss = new Function1DItem(
                // 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.
                @"
					double arg = (x-p[0])/p[1];
					return p[2]*exp(-arg*arg);
				"                );

            gauss.p[0] = 1;             // The position of the curve's peak
            gauss.p[1] = 1;             // The width of the peak
            gauss.p[2] = 4;             // The height of the peak
            plot.Model.Add(gauss);
        }
コード例 #7
0
    public class Demo {     // a class that implements demo routines
        public static void Sin(PlotControl plot)
        {
            // We create a new Function1DItem, set its parameters and add it to the
            // PlotModel plot.
            Function1DItem sin = new Function1DItem();

            // The source represents the body of the following function:
            //
            // double[] p, dfdp;
            // double f(double x) {
            //  ...
            // }
            sin.Source = "return sin(x);";
            sin.Compile();
            sin.Color     = Color.Blue;
            sin.LineWidth = 2;
            plot.Model.Add(sin);
        }
コード例 #8
0
        private void CreateF()
        {
            float lw;

            if (!float.TryParse(lineWidth.Text, out lw))
            {
                lw = 1;
            }
            if (dimensions == Dimensions.One)
            {
                Function1DItem f1 = new Function1DItem();
                f1.Source    = fSource.Text;
                f1.LineStyle = style.LineStyle;
                f1.LineWidth = style.LineWidth;
                f1.Color     = style.Color;
                f            = f1;
            }
            else if (dimensions == Dimensions.Two)
            {
                Function2DItem f1 = new Function2DItem();
                f1.Source   = fSource.Text;
                f1.Gradient = Gradient;
                f           = f1;
            }
            else
            {
                FunctionColorItem f1 = new FunctionColorItem();
                f1.Source = fSource.Text;
                f         = f1;
            }
            f.Name    = name.Text;
            this.Text = name.Text;
            if (oldItem != null)
            {
                f.p = oldItem.p.Clone();
            }
        }
コード例 #9
0
        public static FunctionLineStyleForm New(MainModel m, Function1DItem x)
        {
            // cleanup Forms
            List <Item> closedKeys = new List <Item>();

            foreach (Item y in Forms.Keys)
            {
                if (!Forms[y].Visible)
                {
                    closedKeys.Add(y);
                }
            }
            foreach (Item y in closedKeys)
            {
                Forms.Remove(y);
            }

            FunctionLineStyleForm f = null;

            Forms.TryGetValue(x, out f);
            if (f == null)
            {
                f = new FunctionLineStyleForm(m, x);
            }
            else
            {
                f.Reset(x);
            }
            Forms[x] = f;
            if (f.WindowState == FormWindowState.Minimized)
            {
                f.WindowState = FormWindowState.Normal;
            }
            f.Show();
            f.BringToFront();
            return(f);
        }
コード例 #10
0
ファイル: FitForm.cs プロジェクト: lulzzz/JohnshopesFPlot
        public void ResetPar()
        {
            lock (this) {
                if (function.SelectedItem != null)
                {
                    f = ((DropDownListItem <Function1DItem>)function.SelectedItem).Item;
                }
                else
                {
                    f = null;
                }

                if (data.SelectedItem != null)
                {
                    dataItem = ((DropDownListItem <DataItem>)data.SelectedItem).Item;
                }
                else
                {
                    dataItem = null;
                }
            }
            if (fit.Function != f || fit.Data != dataItem)
            {
                fit.Function = f;
                fit.Data     = dataItem;
                ResetFitp();
                ResetGrid();
                lock (this) {
                    Q.Text     = "0";
                    chisq.Text = Fixed(ChiSquareWidth, 0);
                    neval.Text = "0";
                    oldf       = f;
                }
                ResetButtons();
            }
        }
コード例 #11
0
ファイル: FitForm.cs プロジェクト: lulzzz/JohnshopesFPlot
        void ResetLists()
        {
            lock (this) {
                notifyLevel++;
                Function1DItem f;
                if (function.SelectedItem != null)
                {
                    f = ((DropDownListItem <Function1DItem>)function.SelectedItem).Item;
                }
                else
                {
                    f = null;
                }

                DataItem d;
                if (data.SelectedItem != null)
                {
                    d = ((DropDownListItem <DataItem>)data.SelectedItem).Item;
                }
                else
                {
                    d = null;
                }

                function.Items.Clear();
                data.Items.Clear();
                foreach (Item x in model.Items)
                {
                    if ((x is Function1DItem) && ((Function1DItem)x).Fitable)
                    {
                        function.Items.Add(new DropDownListItem <Function1DItem>(x));
                    }
                    if (x is DataItem)
                    {
                        data.Items.Add(new DropDownListItem <DataItem>(x));
                    }
                }

                DropDownListItem <DataItem> selectedd = DropDownListItem <DataItem> .ListItem(data.Items, d);

                if (selectedd == null && data.Items.Count > 0)
                {
                    selectedd = (DropDownListItem <DataItem>)data.Items[0];
                }

                DropDownListItem <Function1DItem> selectedf = DropDownListItem <Function1DItem> .ListItem(function.Items, f);

                if (selectedf == null && function.Items.Count > 0)
                {
                    selectedf = (DropDownListItem <Function1DItem>)function.Items[0];
                }

                if (data.SelectedItem != selectedd || function.SelectedItem != selectedf)
                {
                    data.SelectedItem     = selectedd;
                    function.SelectedItem = selectedf;
                    ResetPar();
                }

                notifyLevel--;
            }
        }