Example #1
0
        private void CreateGraphOfSlope(ZedGraphControl zgc)
        {
            // Make up some data arrays based on the Sine function
            double        x, y, y1, y2, y3;
            PointPairList list  = new PointPairList();
            PointPairList list1 = new PointPairList();
            PointPairList list2 = new PointPairList();
            PointPairList list3 = new PointPairList();
            PointPair     point = new PointPair();
            LineItem      myCurve;

            //  y' = y^2 - x
            for (x = grSettings.XMin; x <= grSettings.XMax; x = x + grSettings.XIncr)
            {
                for (y = grSettings.YMin; y <= grSettings.YMax; y = y + grSettings.YIncr)
                {
                    y1 = slope(x, y);

                    y2 = y1 + 0.1 * y1;
                    y3 = y1 - 0.1 * y1;

                    list    = new PointPairList();
                    point   = new PointPair();
                    point.X = x;
                    point.Y = y;
                    list.Add(point);
                    FunctionValues.Add(point);

                    myCurve             = myPane.AddCurve("", list, SlopeColor(y1), SymbolType.Default);
                    myCurve.Symbol.Size = 1;
                }
            }
        }
Example #2
0
        private void CreateGraphOfVectorField(ZedGraphControl zgc)
        {
            double        x, y, z;
            PointPairList list  = new PointPairList();
            PointPair     point = new PointPair();
            LineItem      myCurve;

            for (x = grSettings.XMin; x <= grSettings.XMax; x = x + grSettings.XIncr)
            {
                for (y = grSettings.YMin; y <= grSettings.YMax; y = y + grSettings.YIncr)
                {
                    z = vectorfield(x, y);

                    list    = new PointPairList();
                    point   = new PointPair();
                    point.X = x;
                    point.Y = y;
                    list.Add(point);
                    FunctionValues.Add(point);

                    point.X = x + z * Math.Cos(Math.Atan(z));
                    point.Y = y + z * Math.Sin(Math.Atan(z));
                    list.Add(point);
                    FunctionValues.Add(point);

                    myCurve             = myPane.AddCurve("", list, RedBlueSlopeColor(z), SymbolType.Default);
                    myCurve.Symbol.Size = 1;
                }
            }
        }
Example #3
0
        private void CreateGraphOfDerivative(ZedGraphControl zgc)
        {
            // Make up some data arrays based on the Sine function
            double        x, y;
            PointPairList list  = new PointPairList();
            PointPair     point = new PointPair();
            LineItem      myCurve;

            for (x = grSettings.XMin; x <= grSettings.XMax; x = x + grSettings.XIncr)
            {
                y = derivative(x);

                if (!grSettings.SmoothGraph)
                {
                    list = new PointPairList();
                }
                point   = new PointPair();
                point.X = x;
                point.Y = y;
                list.Add(point);
                FunctionValues.Add(point);

                if (!grSettings.SmoothGraph)
                {
                    myCurve             = myPane.AddCurve("", list, SlopeColor(y), SymbolType.Default);
                    myCurve.Symbol.Size = 1;
                }
            }
            if (grSettings.SmoothGraph)
            {
                myCurve             = myPane.AddCurve("", list, Color.Yellow, SymbolType.Default);
                myCurve.Symbol.Size = 1;
            }
        }
Example #4
0
        private void CreateGraphOfCobweb(ZedGraphControl zgc)
        {
            PointPairList list  = new PointPairList();
            PointPair     point = new PointPair();
            LineItem      myCurve;
            LineItem      myCurve2;
            double        x;

            myPane.XAxis.Color     = OppositeGraphColor;
            myPane.YAxis.Color     = OppositeGraphColor;
            myPane.XAxis.IsVisible = true;
            myPane.YAxis.IsVisible = true;

            PointPairList list1 = new PointPairList();
            PointPairList list2 = new PointPairList();

            for (x = grSettings.XMin; x <= grSettings.XMax; x = x + grSettings.XIncr)
            {
                list1.Add(x, x);
                FunctionValues.Add(point);
                myCurve = myPane.AddCurve("", list1, Color.Blue, SymbolType.None);

                list2.Add(x, function(x));
                FunctionValues.Add(point);
                myCurve2 = myPane.AddCurve("", list2, OppositeGraphColor, SymbolType.None);
            }
            CobwebPlots();
        }
Example #5
0
        private void CreateGraphOfIteration(ZedGraphControl zgc)
        {
            PointPairList list  = new PointPairList();
            PointPair     point = new PointPair();
            LineItem      myCurve;
            double        x, y;

            y = grSettings.StartingX;

            for (long n = 1; n <= grSettings.N; n++)
            {
                y = function(y);

                if (!grSettings.SmoothGraph)
                {
                    list = new PointPairList();
                }
                point   = new PointPair();
                point.X = n;
                point.Y = y;
                list.Add(point);
                FunctionValues.Add(point);

                if (!grSettings.SmoothGraph)
                {
                    myCurve             = myPane.AddCurve("", list, OppositeGraphColor, SymbolType.Default);
                    myCurve.Symbol.Size = 1;
                }
            }
            if (grSettings.SmoothGraph)
            {
                myCurve             = myPane.AddCurve("", list, OppositeGraphColor, SymbolType.Default);
                myCurve.Symbol.Size = 1;
            }
        }
Example #6
0
        private void CreateGraphOfFunction(ZedGraphControl zgc)
        {
            PointPairList list  = new PointPairList();
            PointPair     point = new PointPair();
            LineItem      myCurve;
            double        x, y;

            for (x = grSettings.XMin; x <= grSettings.XMax; x = x + grSettings.XIncr)
            {
                y = function(x);

                if (!grSettings.SmoothGraph)
                {
                    list = new PointPairList();
                }
                point   = new PointPair();
                point.X = x;
                point.Y = y;
                list.Add(point);
                FunctionValues.Add(point);

                if (!grSettings.SmoothGraph)
                {
                    myCurve             = myPane.AddCurve("", list, OppositeGraphColor, SymbolType.Default);
                    myCurve.Symbol.Size = 1;
                }
            }
            if (grSettings.SmoothGraph)
            {
                myCurve             = myPane.AddCurve("", list, OppositeGraphColor, SymbolType.Default);
                myCurve.Symbol.Size = 1;
            }
        }
Example #7
0
        private void CreateGraphOfParametricFamily(ZedGraphControl zgc)
        {
            PointPairList list  = new PointPairList();
            PointPair     point = new PointPair();
            LineItem      myCurve;
            double        t;
            double        x, y;

            double c  = grSettings.C1Min;
            double c1 = grSettings.C1Min;
            double c2 = grSettings.C2Min;

            int   colorIndex = 1;
            Color color      = ColorList[colorIndex];

            while (c1 < grSettings.C1Max || c2 < grSettings.C2Max)
            {
                for (t = grSettings.XMin; t <= grSettings.XMax; t = t + grSettings.XIncr)
                {
                    x = parametricfamilyfunction(grSettings.FunctionA, t, c, c1, c2);
                    y = parametricfamilyfunction(grSettings.FunctionB, t, c, c1, c2);

                    if (!grSettings.SmoothGraph)
                    {
                        list = new PointPairList();
                    }
                    point   = new PointPair();
                    point.X = x;
                    point.Y = y;
                    list.Add(point);
                    FunctionValues.Add(point);

                    if (!grSettings.SmoothGraph)
                    {
                        myCurve             = myPane.AddCurve("", list, color, SymbolType.Default);
                        myCurve.Symbol.Size = 1;
                    }
                }

                if (grSettings.SmoothGraph)
                {
                    myCurve             = myPane.AddCurve("", list, color, SymbolType.Default);
                    myCurve.Symbol.Size = 1;
                }

                c          = c + grSettings.C1Incr;
                c1         = c1 + grSettings.C1Incr;
                c2         = c2 + grSettings.C2Incr;
                colorIndex = colorIndex * 3;
                if (colorIndex >= ColorList.Count)
                {
                    colorIndex = 1;
                }
                color = ColorList[colorIndex];
            }
        }
Example #8
0
        private void zedGraphControl1_MouseClick(object sender, MouseEventArgs e)
        {
            if (grSettings.GraphType.Equals(GraphTypes.VectorField))
            {
                this.Cursor = Cursors.WaitCursor;
                double        x, y, z, startZ;
                PointPairList list       = new PointPairList();
                PointPair     point      = new PointPair();
                PointPair     startPoint = new PointPair();
                LineItem      myCurve;

                startPoint.X = e.X;
                startPoint.Y = e.Y;
                y            = startPoint.Y;
                startZ       = vectorfield(startPoint.X, startPoint.Y);
                if (startZ < 0)
                {
                    startZ = -startZ;
                }
                double measure = startZ;
                if (measure < 0.5)
                {
                    measure = 0.5;
                }

                for (x = startPoint.X; x <= measure; measure = measure + grSettings.XIncr)
                {
                    z = vectorfield(x, y);

                    list    = new PointPairList();
                    point   = new PointPair();
                    point.X = x;
                    point.Y = y;
                    list.Add(point);
                    FunctionValues.Add(point);

                    point.X = x + z * Math.Cos(Math.Atan(z));
                    point.Y = y + z * Math.Sin(Math.Atan(z));
                    list.Add(point);
                    FunctionValues.Add(point);

                    myCurve             = myPane.AddCurve("", list, Color.Yellow, SymbolType.Default);
                    myCurve.Symbol.Size = 1;
                }
            }
            this.Cursor = Cursors.Default;
        }
Example #9
0
        private void DrawCircle(ZedGraphControl zgc, double diameter)
        {
            PointPairList list  = new PointPairList();
            PointPair     point = new PointPair();
            LineItem      myCurve;

            for (double theta = 0; theta <= Math.PI * 2; theta = theta + Math.PI * 2 / 360)
            {
                point   = new PointPair();
                point.X = diameter / 2 * Math.Cos(theta);
                point.Y = diameter / 2 * Math.Sin(theta);;
                list.Add(point);
                FunctionValues.Add(point);
            }
            myCurve             = myPane.AddCurve("", list, OppositeGraphColor, SymbolType.None);
            myCurve.Symbol.Size = 1;
        }
Example #10
0
        private void CreateGraphOfParametricFunction(ZedGraphControl zgc)
        {
            PointPairList list  = new PointPairList();
            PointPair     point = new PointPair();
            LineItem      myCurve;
            double        t;
            double        x, y;

            int   colorIndex = 1;
            Color color      = ColorList[colorIndex];

            for (t = grSettings.XMin; t <= grSettings.XMax; t = t + grSettings.XIncr)
            {
                x = parametricfunction(grSettings.FunctionA, t);
                y = parametricfunction(grSettings.FunctionB, t);

                if (!grSettings.SmoothGraph)
                {
                    list = new PointPairList();
                }
                point   = new PointPair();
                point.X = x;
                point.Y = y;
                list.Add(point);
                FunctionValues.Add(point);

                if (!grSettings.SmoothGraph)
                {
                    myCurve             = myPane.AddCurve("", list, color, SymbolType.Default);
                    myCurve.Symbol.Size = 1;
                }
            }

            if (grSettings.SmoothGraph)
            {
                myCurve             = myPane.AddCurve("", list, color, SymbolType.Default);
                myCurve.Symbol.Size = 1;
            }

            colorIndex++;
            if (colorIndex >= ColorList.Count)
            {
                colorIndex = 0;
            }
            color = ColorList[colorIndex];
        }
Example #11
0
        private void CreateGraphOfLevelCurves2(ZedGraphControl zgc)
        {
            double        x, y, z;
            PointPairList list  = new PointPairList();
            PointPair     point = new PointPair();
            LineItem      myCurve;
            double        line = 0;
            double        area = Math.Pow(Math.Pow(grSettings.XIncr, 2) + Math.Pow(grSettings.YIncr, 2), 0.5);

            for (x = grSettings.XMin; x <= grSettings.XMax; x = x + grSettings.XIncr)
            {
                for (y = grSettings.YMin; y <= grSettings.YMax; y = y + grSettings.YIncr)
                {
                    z    = levelcurve(x, y);
                    line = Math.Round(z);

                    list    = new PointPairList();
                    point   = new PointPair();
                    point.X = x;
                    point.Y = y;
                    list.Add(point);
                    FunctionValues.Add(point);

                    if (z >= line - area && z <= line + area)
                    {
                        list.Add(point);
                        FunctionValues.Add(point);

                        myCurve             = myPane.AddCurve("", list, RedBlueSlopeColor(z), SymbolType.Default);
                        myCurve.Symbol.Size = 1;
                    }
                }
                //myCurve = myPane.AddCurve("", list, Color.Red, SymbolType.Default);
                //myCurve.Symbol.Size = 1;
            }
        }
        //TODO : this stuff seems too complex. Make it look simler.
        private void Functions_CollectionChanged(object sender, NotifyCollectionChangingEventArgs e)
        {
            var function = (IFunction)e.Item;

            switch (e.Action)
            {
            case NotifyCollectionChangeAction.Add:

                FunctionValues.Add(null);
                /* Get the components of a function. Not of variables */
                if (!(function is IVariable))
                {
                    foreach (IVariable component in function.Components)
                    {
                        if (Functions.Contains(component))
                        {
                            continue;
                        }
                        Functions.Add(component);
                    }
                }

                foreach (IVariable argument in function.Arguments)
                {
                    if (argument.Store != this)
                    {
                        if (Functions.Contains(argument))
                        {
                            continue;
                        }
                        Functions.Add(argument);
                    }
                }

                if (function is IVariable)
                {
                    var variable = (IVariable)function;

                    var variableValues = variable.FixedSize == 0 ? null : variable.Values;

                    // avoid unnecessary calls for better performance
                    var array = (variableValues == null || variableValues.Count == 0)
                            ? variable.CreateStorageArray()
                            : variable.CreateStorageArray(variable.Values);

                    FunctionValues[e.Index] = array;

                    variable.CachedValues = array;

                    SubscribeToArray(array);

                    // register all variables which for the newly added is an argument
                    IEnumerable <IFunction> dependendFunctions =
                        functions.Where(f => f.Arguments.Contains(variable) && f is IVariable);
                    foreach (IVariable dependentVariable in dependendFunctions)
                    {
                        //DependentVariables[variable].Add(dependentVariable);
                        UpdateVariableSize(dependentVariable);
                    }
                }

                function.Store = this;

                break;

            case NotifyCollectionChangeAction.Remove:

                IMultiDimensionalArray multiDimensionalArray = FunctionValues[e.Index];
                UnsubscribeFromArray(multiDimensionalArray);

                FunctionValues.RemoveAt(e.Index);

                //evict the function from the store. Reset arguments and components list to prevent synchronization.

                function.Arguments  = new EventedList <IVariable>();
                function.Components = new EventedList <IVariable>();
                function.Store      = null;

                //IFunctionStore newStore = new MemoryFunctionStore();
                //newStore.Functions.Add(function);
                break;

            case NotifyCollectionChangeAction.Replace:
                throw new NotSupportedException();
            }
            UpdateAutoSortOnArrays();
            UpdateDependentVariables();
        }