#include #include #include #include double LeftRS(int u) { double dx = 2.0 / u; double sum = 0.0; double a = 0; double b = 0; int i = 1; while (i <= u) { a = (i - 1) * dx; b = std::pow(a, 3) + 1; sum += b * dx; i++; } return sum; } double MidPointRS(int u) { double dx = 2.0 / u; double sum = 0.0; double a = 0; double b = 0; int i = 1; while (i <= u) { a = (i - 0.5) * dx; b = std::pow(a, 3) + 1; sum += b * dx; i++; } return sum; } double RightRS(int u) { double dx = 2.0 / u; double sum = 0.0; double a = 0; double b = 0; int i = 1; while (i <= u) { a = i * dx; b = std::pow(a, 3) + 1; sum += b * dx; i++; } return sum; } int main() { std::ofstream File("riemannsum.csv"); File << "n,Left,Right,Midpoint\n"; for (int i = 20; i <= 10000; i += 20) { File << i << ',' << std::setprecision(11) << LeftRS(i) << ',' << RightRS(i) << ',' << MidPointRS(i) << '\n'; } std::cin.get(); return 0; } Copy
Comments
Post a Comment