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
|
#include <iostream>
#include <cstdlib>
#include "math.h"
using namespace std;
int findX(double x, double sum, int r, int k, double a, double b, double h, double n);
int findY(double x, double sum, int r, int k, double a, double b, double h, double n, double y);
int findSum(double x, double sum, int r, int k, double a, double b, double h, double n);
int findMod(double x, double sum, int r, int k, double a, double b, double h, double n, double mod, double y);
int main()
{
double a, b, x, h, r, sum, 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;
int findX(double x, double sum, int r, int k, double a, double b, double h, double n);
int findSum(double x, double sum, int r, int k, double a, double b, double h, double n);
int findY(double x, double sum, int r, int k, double a, double b, double h, double n, double y);
int findMod(double x, double sum, int r, int k, double a, double b, double h, double n, double mod, double y);
system("pause");
}
int findX(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<<"x = "<<x<<endl;
}
}
return x;
}
int 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;
}
int findY(double x, double sum, int r, int k, double a, double b, double h, double n, double y)
{
y=pow(exp(x),2*x);
cout<<"Y = "<<y<<endl;
return y;
}
int findMod(double x, double sum, int r, int k, double a, double b, double h, double n, double mod, double y)
{
mod=fabs(y-sum);
cout<<"|Y(x)-Sum(x)| = "<<mod<<endl;
return sum;
}
|