Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // semestrovaya_2.1.cpp : Defines the entry point for the console application.
- // Методичка 2: 1.5 (в); (е); (ж);
- #include "stdafx.h"
- #include <iostream>
- #include <conio.h>
- #include <cmath>
- #include <iomanip>
- #include <fstream>
- using namespace std;
- double fi = 1;
- int qwe;
- void create(ifstream&f, double *x, int n);
- void show(ofstream&f, double *x, int n);
- inline double sqr(double x);
- inline double g(double x);
- inline double h(double z);
- double sum_g(double *x, int M);
- double T(double h);
- void change_fi();
- void change_x(double *x, double t, int M);
- int main()
- {
- setlocale(0, "Russian");
- ifstream in("in.txt");
- ofstream out("out.txt");
- int m; //"Введите количество верхних границ интеграла t:\nm = ";
- in >> m;
- int M; //"Введите количесвто точек x для полученя значения интеграла \nM = ";
- in >> M;
- double *t = new double[m];
- create(in, t, m);
- in.close();
- double *ans = new double[m]; //массив значений интеграла в точках t[i] : (i=[0;m]);
- double *x = new double [M];
- for (int i(0); i < m; i++) //для проверки
- {
- change_x(x, t[i], M);
- }
- for (int i(0); i < m; i++)
- {
- change_x(x, t[i], M);
- ans[i] = (t[i] - 1) * (sum_g(x, M) / M);
- }
- for (int i(0); i < m; i++)
- {
- cout << "Значение интеграла #" << i + 1 << " = " << ans[i] << endl;
- }
- show(out, ans, m);
- system("pause");
- return 0;
- }
- void create(ifstream&f, double *x, int n)
- {
- if (!f)
- {
- cout << "Can't open file" << endl;
- exit(0);
- }
- for (int i(0); i < n; i++)
- f >> x[i];
- }
- void show(ofstream&f, double *x, int n)
- {
- for (int i(0); i <n; i++)
- {
- f << x[i] << ' ';
- }
- f << endl;
- }
- inline double sqr(double x) //Функция возведения в квадрат;
- {
- return x * x;
- }
- inline double g(double x) //данная функция g(x);
- {
- return x;
- //return sqr(x) + x + 1;
- }
- inline double h(double z) //Данная функция h(z);
- {
- //return sqrt(abs(1 - z));
- return (sin(z) + sqr(sin(z))) / 2;
- }
- double sum_g(double *x, int M) // Сумма значений ф-ии g(x) в произвольных точках х[i];
- {
- double s(0);
- for (int i(0); i < M; i++)
- {
- s += g(x[i]);
- }
- return s;
- }
- double T(double h)
- {
- int n = 10;
- int U[10], V[10];
- double s = 0;
- float q = 0.5;
- for (int i(0); i < n; i++)
- {
- U[i] = (int)(h * 2);
- if (h * 2 >= 1)
- h = h * 2 - 1;
- else h = h * 2;
- }
- for (int i(0); i < n - 1; i++)
- if (U[i] == U[i + 1])
- V[i] = 0;
- else
- V[i] = 1;
- for (int i(0); i < n - 1; i++)
- {
- s += V[i] * q;
- q *= 0.5;
- }
- return s;
- }
- void change_fi() // число фи, образованный случайно, для определения числа x[i];
- {
- fi = T(h(fi));
- }
- void change_x(double *x, double t, int M)
- {
- for (int i(0); i < M; i++)
- {
- change_fi();
- x[i] = 1 + (t - 1) * fi;
- }
- }
- /*void perevod(double h)
- {
- int n = 10;
- int U[10], V[10];
- double s = 0;
- cout << "0.";
- for (int i(0); i < n; i++)
- {
- U[i] = (int)(h * 2);
- if (h * 2 >= 1)
- h = h * 2 - 1;
- else h = h * 2;
- cout << U[i];
- }
- cout << endl << endl;
- for (int i(0); i < n - 1; i++)
- if (U[i] == U[i + 1])
- V[i] = 0;
- else
- V[i] = 1;
- for (int i(0); i < n - 1; i++)
- cout << V[i];
- float q = 0.5;
- for (int i(0); i < n - 1; i++)
- {
- s += V[i] * q;
- q *= 0.5;
- }
- cout << endl << s;
- }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement