S
S
soja2021-04-12 21:46:19
WPF
soja, 2021-04-12 21:46:19

How to plot in c# wpf?

I need to create a program for displaying graphs
, one I got, and the one with the root in a straight line is built
since I just started, it's hard to immediately notice the error,
help in any way you can)))))

private void Vpered_Click_1(object sender, RoutedEventArgs e)
        {
            Polyline pl = new Polyline();
            pl.Stroke = Brushes.Red;
            pl.StrokeThickness = 2;
            Polyline pl2 = new Polyline();
            pl2.Stroke = Brushes.Blue;
            pl2.StrokeDashArray.Add(5);
            pl2.StrokeThickness = 2;
            int x_smeshenie = 700 / 2;
            int y_smeshenie = 150;
            Line lnx = new Line
            {
                X1 = 100,
                Y1 = y_smeshenie,
                X2 = 600,
                Y2 = y_smeshenie,
                Stroke = Brushes.Black,
                StrokeThickness = 1
            };
            Line lny = new Line
            {
                X1 = x_smeshenie,
                Y1 = 0,
                X2 = x_smeshenie,
                Y2 = 300,
                Stroke = Brushes.Black,
                StrokeThickness = 1
            };
            for (double x = -8; x <= 4; x += 0.01)
            {
                double new_y = (x * x * x + 8 * x * x + 16 * x + 128) / (32 + Math.Sin(x));
                pl.Points.Add(new Point(x * 25 + x_smeshenie, -new_y * 25 + y_smeshenie));
            }
            for (double x = -8; x <= 4; x += 0.01)
            {
                double new_y = Math.Pow(x * x * (x + 1), (1 / 3));
                pl2.Points.Add(new Point(x * 25 + x_smeshenie, -new_y * 25 + y_smeshenie));
            }
            g.Children.Add(lnx);
            g.Children.Add(lny);
            g.Children.Add(pl);
            g.Children.Add(pl2);
            g.ClipToBounds = true;
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
twobomb, 2021-04-12
@soja

Because it gives 0, and you always raise to the zero power and you always have one there, you need to set Well, then there will be a second jamb, while the cycle goes from -8 to -1, you will have negative numbers and it turns out that you will try to raise a negative number to the power of 0.3 and get NaN, so put a cycle from 0 to 4+ so that you don't get negative numbers, or make the exponent non-fractional (1 / 3)
(1f/ 3f)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question