A
A
ars-bars2018-04-27 13:10:49
C++ / C#
ars-bars, 2018-04-27 13:10:49

C# WinForms Chart - Quadratic Spline Function?

Hello!
I ask for help - to understand the following question.
There is a quadratic function given as y = 0.5773 * x^2 + 0.6183 * x - 0.0331.
There are X points:
0.057
0.177
0.283
1.087
There is a Chart component. ChartType for the chart is set to Spline.
The output is the following picture:
5ae2f699254f9256716000.jpeg
What kind of extra bend in the graph? How to get rid of it?
Need a smooth square line.
I am also attaching the source code.

public Form1()
        {
            double[] X = new double[4] { 0.057, 0.177, 0.283, 1.087 };
            double[] Y = new double[4];

            for (int i = 0; i < X.Length; i++)
                Y[i] = CalcPolynom(X[i], new double[3] { -0.0331, 0.6183, 0.5773 });


            InitializeComponent();

            Series s = chart1.Series[0];

            for (int i = 0; i < X.Length; i++)
                s.Points.AddXY(X[i], Y[i]);
        }

        double CalcPolynom(double x, double[] coeffs)
        {
            double y = 0;
            double x_interim = 1;

            for (int i = 0; i < coeffs.Length; i++)
            {
                y += x_interim * coeffs[i];
                x_interim *= x;
            }

            return y;
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Codebaker, 2018-04-29
@Codebaker

Elementary, you declare an array of points X, but to calculate Y you use a different set of values ​​(an anonymous array for 3 values: new double[3] { -0.0331, 0.6183, 0.5773 }) - in it just the second point is slightly to the right than the last .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question