Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <math.h>
- using namespace std;
- double Y(double x)
- {
- double Y = (1+2*x*x)*exp(x*x);
- return Y;
- }
- double Sum(int n, double x)
- {
- double Sum=1;
- double v=1;
- for (int k=1;k<=n;k++)
- {
- v=v*x*x*(2*k+1)/(k*(2*k-1));
- Sum+=v;
- }
- return Sum;
- }
- void Out_Rez(int vibor, double a, double b, double h, double (*pY)(double x) ,double (*pSum)(int n, double x))
- {
- double x, modul;
- int i = 0;
- switch (vibor)
- {
- case 1:
- cout << "\nШаг\tx:\tY(x):" << endl;
- for (x=a; x<=b; x+= h)
- {
- cout << 1 + i << "\t" << setprecision(2) << x << "\t" << setprecision(6) << Y(x) << endl;
- i++;
- }
- break;
- case 2:
- int n;
- cout << "Введите значение параметра n: " << endl;
- cout << "n = ";
- cin >> n;
- cout << "\nШаг\tx:\tS(x):" << endl;
- for (x=a; x<=b; x+= h)
- {
- cout << 1 + i << "\t" << setprecision(2) << x << "\t" << setprecision(6) << Sum(n,x) << endl;
- i++;
- }
- break;
- case 3:
- cout << "Введите значение параметра n: " << endl;
- cout << "n = ";
- cin >> n;
- cout << "\nШаг\tx:\t\tY(x):\t\tS(x):\t\t|Y(x) - S(x)|:" << endl;
- for (x=a; x<=b; x+= h)
- {
- modul = fabs(Y(x) - Sum(n,x));
- cout << 1 + i << "\t" << setw(2) << x << "\t\t" << setw(6) << Y(x) << "\t\t" << Sum(n,x) << "\t\t" << modul << endl;
- i++;
- }
- break;
- }
- }
- int main()
- {
- setlocale(LC_ALL, "rus");
- int vibor;
- double a, b, h;
- cout << "Выберите функцию: \n 1) Y(x) \n 2) S(x) \n 3) |Y(x) - S(x)|" << endl;
- cin >> vibor;
- while (vibor<0 || vibor>3)
- {
- cout<<"Ошибка! Неправильный ввод."<<endl;
- cout << "Выберите функцию: \n 1) Y(x) \n 2) S(x) \n 3) |Y(x) - S(x)|" << endl;
- cin >> vibor;
- }
- cout << "Введите h: "; cin>>h;
- cout<< "Введите a: "; cin>>a;
- cout<< "Введите b: "; cin>>b;
- while(a==0 && b==0 || h==0)
- {
- cout<<"Результат не может быть достигнут!"<<endl;
- cout<<"Ошибка! Неправильный ввод."<<endl;
- cout << "Введите h: "; cin>>h;
- cout<< "Введите a: "; cin>>a;
- cout<< "Введите b: "; cin>>b;
- }
- Out_Rez(vibor, a, b, h, &Y, &Sum);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement