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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#include <complex>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <type_traits>
template< typename T, typename SCALAR > inline
typename std::enable_if< !std::is_same<T,SCALAR>::value, std::complex<T> >::type
operator* ( const std::complex<T>& c, SCALAR n ) { return c * T(n) ; }
template< typename T, typename SCALAR > inline
typename std::enable_if< !std::is_same<T,SCALAR>::value, std::complex<T> >::type
operator* ( SCALAR n, const std::complex<T>& c ) { return T(n) * c ; }
template< typename T, typename SCALAR > inline
typename std::enable_if< !std::is_same<T,SCALAR>::value, std::complex<T> >::type
operator/ ( const std::complex<T>& c, SCALAR n ) { return c / T(n) ; }
template< typename T, typename SCALAR > inline
typename std::enable_if< !std::is_same<T,SCALAR>::value, std::complex<T> >::type
operator/ ( SCALAR n, const std::complex<T>& c ) { return T(n) / c ; }
using namespace std;
complex<double> fct(complex<double> z);
int main()
{
complex<double> a, b, h, integral, sum1, sum2, sumt, error, z;
int n;
cout << "Die Integrationsgrenzen und Die Anzahl der Schritte: " << endl;
a = {1,1};
b = {3,3};
n = 1000;
h = (b-a)/n;
sum1 = fct(a) + fct(b);
for(int l = 0; l < n; l++)
{
if(l%2 == 0)
{
sum1 += fct(a + l * h);
}
else
{
sum2 += fct( a + l * h);
}
sumt = h/3. * ( fct(a) + fct(b) + 4. * sum2 + 2. * sum1);
}
cout << a <<" "<< b << endl;
cout << h << endl;
cout << "the Integral is: " <<sumt;
return 0;
}
complex<double> fct(complex<double> z)
{
return z;
}
|