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 65 66 67 68 69 70 71 72 73
|
#include <iostream>
#include <cstdlib>
#include "math.h"
using namespace std;
double findX(double x, double a, double b, double h)
{
for(x = a; x<=b; x+=h)
{
cout<<"x = "<<x<<" "<<endl;
}
return x;
}
double findY(double x, double a, double b, double h, double n, double y)
{
for(x = a; x<=b; x+=h)
{
y=pow(exp(x),2*x);
cout<<"Y = "<<y<<" "<<endl;
}
return y;
}
double findSum(double x, double sum, int r, int k, double a, double b, double h, double n)
{
for(x = a; x<=b; x+=h)
{
r = sum = 1;
for(k = 1; k<=n; k++)
{
r=2*r*x/k;
sum+=r;
cout<< "Sum = "<<sum<<" "<<endl;
}
}
return sum;
}
double findMod(double x, double sum, int r, int k, double a, double b, double h, double n, double mod, double y)
{
for(x = a; x<=b; x+=h)
{
r = sum = 1;
for(k = 1; k<=n; k++)
{
r=2*r*x/k;
sum+=r;
y=pow(exp(x),2*x);
{
mod=fabs(y-sum);
cout<<"|Y(x)-Sum(x)| = "<<mod<<" "<<endl;
}
}
}
return mod;
}
int main()
{
double a, b, x, h, r = 1, sum = 1, y, mod;
int n, k;
cout<<"Input a = ";
cin>>a;
cout<<"Input b = ";
cin>>b;
cout<<"Input h = ";
cin>>h;
cout<<"Input n = ";
cin>>n;
cout<<endl;
x = findX (x, a, b, h);
y = findY (x, a, b, h, n, y);
sum = findSum ( x, r, k, a, b, h, n, sum);
mod = findMod (x, sum, r, k, a, b, h, n, y, mod);
system ("pause");
}
|