mam pytanie jak zinterpretowac wychodzące wyniki???Czy powinny być one aż takie duże. jak z tego programu wyliczyć błąd względny?

``````#include <iostream>
using namespace std;

template <class T>
T f(T x)
{
return (2*x*x)+3*x+1;
}

template <class T>
void functionTwo(int n)
{
T h = 1.0/T(n);
T sum = 0.0;
for(int i=0; i<n; i++)
{
T x=T(i)+h;
sum+=f<T>(x);
}
}

int main()
{
int n = 100;
for(int i=1;i<n;i++){
cout<<"float, n = "<<i;
functionTwo<float>(i);
cout<<"double, n = "<<i;
functionTwo<double>(i);
}
return 0;
}
``````

wyniki:
float, n = 1 blad = 0
double, n = 1 blad = 0
float, n = 2 blad = 2
double, n = 2 blad = 2
float, n = 3 blad = -1.66667
double, n = 3 blad = -1.66667
float, n = 4 blad = -14.5
double, n = 4 blad = -14.5
float, n = 5 blad = -40.4
double, n = 5 blad = -40.4
float, n = 6 blad = -83.3333
double, n = 6 blad = -83.3333
float, n = 7 blad = -147.286
double, n = 7 blad = -147.286
float, n = 8 blad = -236.25
double, n = 8 blad = -236.25
float, n = 9 blad = -354.222
double, n = 9 blad = -354.222
float, n = 10 blad = -505.2
double, n = 10 blad = -505.2
float, n = 11 blad = -693.182
double, n = 11 blad = -693.182
float, n = 12 blad = -922.167
double, n = 12 blad = -922.167
float, n = 13 blad = -1196.15
double, n = 13 blad = -1196.15
float, n = 14 blad = -1519.14
double, n = 14 blad = -1519.14
float, n = 15 blad = -1895.13
double, n = 15 blad = -1895.13
float, n = 16 blad = -2328.12
double, n = 16 blad = -2328.12
float, n = 17 blad = -2822.12
double, n = 17 blad = -2822.12
float, n = 18 blad = -3381.11
double, n = 18 blad = -3381.11
float, n = 19 blad = -4009.11
double, n = 19 blad = -4009.11
float, n = 20 blad = -4710.1
double, n = 20 blad = -4710.1
float, n = 21 blad = -5488.1
double, n = 21 blad = -5488.1
float, n = 22 blad = -6347.09
double, n = 22 blad = -6347.09
float, n = 23 blad = -7291.09
double, n = 23 blad = -7291.09
float, n = 24 blad = -8324.08
double, n = 24 blad = -8324.08
float, n = 25 blad = -9450.08
double, n = 25 blad = -9450.08
float, n = 26 blad = -10673.1
double, n = 26 blad = -10673.1
float, n = 27 blad = -11997.1
double, n = 27 blad = -11997.1
float, n = 28 blad = -13426.1
double, n = 28 blad = -13426.1
float, n = 29 blad = -14964.1
double, n = 29 blad = -14964.1
float, n = 30 blad = -16615.1
double, n = 30 blad = -16615.1
float, n = 31 blad = -18383.1
double, n = 31 blad = -18383.1
float, n = 32 blad = -20272.1
double, n = 32 blad = -20272.1
float, n = 33 blad = -22286.1
double, n = 33 blad = -22286.1
float, n = 34 blad = -24429.1
double, n = 34 blad = -24429.1
float, n = 35 blad = -26705.1
double, n = 35 blad = -26705.1
float, n = 36 blad = -29118.1
double, n = 36 blad = -29118.1
float, n = 37 blad = -31672.1
double, n = 37 blad = -31672.1
float, n = 38 blad = -34371.1
double, n = 38 blad = -34371.1
float, n = 39 blad = -37219.1
double, n = 39 blad = -37219.1
float, n = 40 blad = -40220.1
double, n = 40 blad = -40220.1
float, n = 41 blad = -43378
double, n = 41 blad = -43378
float, n = 42 blad = -46697
double, n = 42 blad = -46697
float, n = 43 blad = -50181
double, n = 43 blad = -50181
float, n = 44 blad = -53834
double, n = 44 blad = -53834
float, n = 45 blad = -57660
double, n = 45 blad = -57660
float, n = 46 blad = -61663
double, n = 46 blad = -61663
float, n = 47 blad = -65847
double, n = 47 blad = -65847
float, n = 48 blad = -70216
double, n = 48 blad = -70216
float, n = 49 blad = -74774
double, n = 49 blad = -74774
float, n = 50 blad = -79525
double, n = 50 blad = -79525
float, n = 51 blad = -84473
double, n = 51 blad = -84473
float, n = 52 blad = -89622
double, n = 52 blad = -89622
float, n = 53 blad = -94976
double, n = 53 blad = -94976
float, n = 54 blad = -100539
double, n = 54 blad = -100539
float, n = 55 blad = -106315
double, n = 55 blad = -106315
float, n = 56 blad = -112308
double, n = 56 blad = -112308
float, n = 57 blad = -118522
double, n = 57 blad = -118522
float, n = 58 blad = -124961
double, n = 58 blad = -124961
float, n = 59 blad = -131629
double, n = 59 blad = -131629
float, n = 60 blad = -138530
double, n = 60 blad = -138530
float, n = 61 blad = -145668
double, n = 61 blad = -145668
float, n = 62 blad = -153047
double, n = 62 blad = -153047
float, n = 63 blad = -160671
double, n = 63 blad = -160671
float, n = 64 blad = -168544
double, n = 64 blad = -168544
float, n = 65 blad = -176670
double, n = 65 blad = -176670
float, n = 66 blad = -185053
double, n = 66 blad = -185053
float, n = 67 blad = -193697
double, n = 67 blad = -193697
float, n = 68 blad = -202606
double, n = 68 blad = -202606
float, n = 69 blad = -211784
double, n = 69 blad = -211784
float, n = 70 blad = -221235
double, n = 70 blad = -221235
float, n = 71 blad = -230963
double, n = 71 blad = -230963
float, n = 72 blad = -240972
double, n = 72 blad = -240972
float, n = 73 blad = -251266
double, n = 73 blad = -251266
float, n = 74 blad = -261849
double, n = 74 blad = -261849
float, n = 75 blad = -272725
double, n = 75 blad = -272725
float, n = 76 blad = -283898
double, n = 76 blad = -283898
float, n = 77 blad = -295372
double, n = 77 blad = -295372
float, n = 78 blad = -307151
double, n = 78 blad = -307151
float, n = 79 blad = -319239
double, n = 79 blad = -319239
float, n = 80 blad = -331640
double, n = 80 blad = -331640
float, n = 81 blad = -344358
double, n = 81 blad = -344358
float, n = 82 blad = -357397
double, n = 82 blad = -357397
float, n = 83 blad = -370761
double, n = 83 blad = -370761
float, n = 84 blad = -384454
double, n = 84 blad = -384454
float, n = 85 blad = -398480
double, n = 85 blad = -398480
float, n = 86 blad = -412843
double, n = 86 blad = -412843
float, n = 87 blad = -427547
double, n = 87 blad = -427547
float, n = 88 blad = -442596
double, n = 88 blad = -442596
float, n = 89 blad = -457994
double, n = 89 blad = -457994
float, n = 90 blad = -473745
double, n = 90 blad = -473745
float, n = 91 blad = -489853
double, n = 91 blad = -489853
float, n = 92 blad = -506322
double, n = 92 blad = -506322
float, n = 93 blad = -523156
double, n = 93 blad = -523156
float, n = 94 blad = -540359
double, n = 94 blad = -540359
float, n = 95 blad = -557935
double, n = 95 blad = -557935
float, n = 96 blad = -575888
double, n = 96 blad = -575888
float, n = 97 blad = -594222
double, n = 97 blad = -594222
float, n = 98 blad = -612941
double, n = 98 blad = -612941
float, n = 99 blad = -632049
double, n = 99 blad = -632049