#include <iostream> #include <math.h> using namespace std; class Simpsons1b3 { public: Simpsons1b3() { k = 2; } void askInterval(); void solve(); double f(double x); void findH(); void findX1(); private: double I,h,xn,x0,k,x1; }; void Simpsons1b3::askInterval() { cout << "Enter Xn: "; cin >> xn; cout << "Enter X0: "; cin >> x0; } void Simpsons1b3::findH() { h= (xn - x0)/k; } void Simpsons1b3::findX1() { x1 = x0 + h; } double Simpsons1b3::f(double x) { return exp(x); } void Simpsons1b3::solve() { askInterval(); findH(); findX1(); I = h / 3.0 * ( f(x0) +4 * f(x1) + f(xn) ); cout << endl << "The required answer is : " << I << endl; } int main() { Simpsons1b3 s1; s1.solve(); return 0; }
C and C++ programs, games, softwares. Easy programming guide. Learn to code and enjoy coding in CoderNepal
Home » Simpson's 1/3 Rule
Simpson's 1/3 Rule
This is the solution finding Integration using Simpson's 1/3 Rule
Subscribe to:
Posts (Atom)
No comments:
Post a Comment