if (k>1) C1 = C2;
if (k>2) R1 = R2;
k++; h/=2;
f = 0; x = a + h/2;
while (x<b)
{
f += fx(x);
x += h;
}
T2 = (T1 + h * f) / 2;
S2 = T2 + (T2 - T1)/3;
if (k==1) continue;
C2 = S2 + (S2 - S1)/15;
if (k==2) continue;
R2 = C2 + (C2 - C1)/63;
}
system("pause");
return 0;
}
B
.中心加速求导:
// y = e^ x
#include <iostream>
#include <cmath>
#define eps 1e-6
using namespace std;
double G(double h)
{
if (h<0) h = -h;
return (exp(1+h) - exp(1-h))/(2*h);
}
int main()
{
double h;
cin>>h;
double S1, S2, T1, T2, C1, C2, R1, R2;
double x, f;
T2 = T1 = G(h);
int k = 0;
R1=0; R2=1; h *= 2;
while (fabs(R2-R1)>eps)
{
cout<<T2<<" ";
if (k>1) cout<<S2<<" ";
if (k>2) cout<<C2<<" ";
if (k>3) cout<<R2;
cout<<endl;
T1 = T2;
S1 = S2;
if (k>1) C1 = C2;
if (k>2) R1 = R2;
k++; h/=2;
T2 = G(h);
S2 = T2 + (T2 - T1)/3;
if (k==1) continue;
C2 = S2 + (S2 - S1)/15;
if (k==2) continue;
R2 = C2 + (C2 - C1)/63;
}
system("pause");
return 0;
}
if (k>1) C1 = C2;
if (k>2) R1 = R2;
k++; h/=2;
f = 0; x = a + h/2;
while (x<b)
{
f += fx(x);
x += h;
}
T2 = (T1 + h * f) / 2;
S2 = T2 + (T2 - T1)/3;
if (k==1) continue;
C2 = S2 + (S2 - S1)/15;
if (k==2) continue;
R2 = C2 + (C2 - C1)/63;
}
system("pause");
return 0;
}
B
.中心加速求导:
// y = e^ x
#include <iostream>
#include <cmath>
#define eps 1e-6
using namespace std;
double G(double h)
{
if (h<0) h = -h;
return (exp(1+h) - exp(1-h))/(2*h);
}
int main()
{
double h;
cin>>h;
double S1, S2, T1, T2, C1, C2, R1, R2;
double x, f;
T2 = T1 = G(h);
int k = 0;
R1=0; R2=1; h *= 2;
while (fabs(R2-R1)>eps)
{
cout<<T2<<" ";
if (k>1) cout<<S2<<" ";
if (k>2) cout<<C2<<" ";
if (k>3) cout<<R2;
cout<<endl;
T1 = T2;
S1 = S2;
if (k>1) C1 = C2;
if (k>2) R1 = R2;
k++; h/=2;
T2 = G(h);
S2 = T2 + (T2 - T1)/3;
if (k==1) continue;
C2 = S2 + (S2 - S1)/15;
if (k==2) continue;
R2 = C2 + (C2 - C1)/63;
}
system("pause");
return 0;
}