Integration can be used to find areas, volumes, central points and many useful things. But it is often used to find the area under the graph of a function like this:
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
class Program { static double Integral(double a, double b, double c, double xa, double xb, int h) { double xp, y, s, result = 0, g = (xb - xa) / h; for (int i = 0; i < h; i++) { xp = xa + g; y = (a * Math.Pow(xp, 2)) + (b * xp) + c; s = g * y; result += s; } return result; } static void Main(string[] args) { Console.WriteLine("C# Integral"); Console.WriteLine(Integral(1, 4, 2, 10, 50, 100)); Console.ReadLine(); } } |