Realization of the class of a fixed integration calculation! Classic!

xiaoxiao2021-03-06  38

It can be used for approximately calculating a dollar function, and a function pointer type is implemented, making it more flexible! TypedEf Double (* PFN) (double); Class Integral {Double Lower; // Point Minister Double Upper; // Integral upper limit PFN integrand; // integration function public: integral (double a, double b, pfn f) {loc = a; Upper = b; integrand = f;} double lowbd () const {return lower;} Double UPD () const {return Upper;} Void ChangeBd (Double, Double); // Change the integral upper and lower limit Double Trapezoidal (int) const; // integrated, parameter defines the size of the step size of Friend Double Simpson (Integral, Int); // friend function declaration};

Inline void integral :: changebd (double a, double b) {loc = a; Upper = b;}

Double Integral :: Trapezoidal (int N) const {double h = (Upper-limited) / N; double sum = integrand (limited) * 0.5; for (int i = 1; i

Double Simpson (IgRAL IG, INT N) {Double H = (Ig.upper-Ig.Lower) / N; Double Sum = Ig.integragrand (Ig.Lower) * 0.5; for (INT I = 1; I

Double Summid = 0.0; for (i = 1; i <= n; i ) Summid = Ig.integrand (Ig.Lower (i-0.5) * h);

Return (SUM 2 * Summid) * h / 3.0;}

转载请注明原文地址:https://www.9cbs.com/read-62817.html

New Post(0)