I want to plot any polynomial function in C# using the console application, without using any windows or forms, I searched a lot but all I found was in window application or involving MATLAB and what I want is something just in the console.
I want it to plot any polynomial function given, for example; the coefficients are stored in an array, and i want to plot the function related to it, for example:
The array is:
double[] array = new double[4] { 2 , 0 , -4 , 3 };
Then the function is: 3X^3 – 4X^2 + 2
And it will be plotted on the XY-Plane like this:
For Example: X + 1
https://i.stack.imgur.com/SD3tb.jpg
Any help is appreciated.
Update:
Using the method you provided, I tried this code:
WriteAt("|", 40, 0);
WriteAt("|", 40, 1);
WriteAt("|", 40, 2);
WriteAt("|", 40, 3);
WriteAt("|", 40, 4);
WriteAt("|", 40, 5);
WriteAt("|", 40, 6);
WriteAt("|", 40, 7);
WriteAt("|", 40, 8);
WriteAt("|", 40, 9);
WriteAt("-----------------------------------------", 20, 10);
WriteAt("|", 40, 11);
WriteAt("|", 40, 12);
WriteAt("|", 40, 13);
WriteAt("|", 40, 14);
WriteAt("|", 40, 15);
WriteAt("|", 40, 16);
WriteAt("|", 40, 17);
WriteAt("|", 40, 18);
WriteAt("|", 40, 19);
WriteAt("|", 40, 20);
WriteAt("*", 32, 12);
WriteAt("*", 34, 11);
WriteAt("*", 36, 10);
WriteAt("*", 38, 9);
WriteAt("*", 40, 8);
WriteAt("*", 42, 7);
WriteAt("*", 44, 6);
WriteAt("*", 46, 5);
WriteAt("*", 48, 4);
And I got this:
https://i.stack.imgur.com/cqLz2.jpg
So, now I have to give the WriteAt function the points that must be drawn but putting in mind that the origin is (40,10) in my plotting ??
I subtract 2 from the x-axis because the “-” is half the size of the “|” so the plot will be kinda scaled.
You need to use Console.SetCursorPosition and draw “*” as needed as if you have something like 80×25 display with pixels.
You will need to scale your
xandyaxis accordingly to fit into screen space. Don’t forget thatyon screen is down, when on normal drawings it is up – need to inverse in addition to shift when computing screen position (same as regular graphics).Essentials of sample available in the above MSDN article: