Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <fstream>
- #include <cmath>
- using namespace std;
- const double PI = 3.1415926535897932384626433832795;
- const double step_x = 0.001;
- const int max_number = 100;
- const double step_t = 0.00001;
- const double length = 100;
- double q_array[max_number];
- ////////////////////////////////////////////////////////
- //ищем q и в масив
- ////////////////////////////////////////////////////////
- double f(double x)
- {
- return (cos(x) / sin(x)) - x;
- }
- double bissection (int number)
- {
- double x_1, x_2, half_x_1_x_2 ;
- x_1 = (number * PI) + step_x;
- x_2 = (number * PI) + PI - step_x;
- while (abs(x_1 - x_2) > step_x) {
- half_x_1_x_2 = (x_1 + x_2) / 2;
- if (f(x_1) * f(half_x_1_x_2) < 0)
- x_2 = half_x_1_x_2;
- else
- x_1 = half_x_1_x_2;
- }
- return abs(x_1 + x_2) / 2;
- }
- void finding_qk () {
- for (int i = 0; i < max_number; i++) {
- ::q_array[i] = 0;
- }
- for (int i = 0; i < max_number; i++) {
- ::q_array[i] = bissection(i);
- }
- }
- double calculate(double q, double x, double t) {
- double result = 0;
- result = (4 / (2 * q + sin(2 * q)))*(sin(q) + 2 * sin(q / 2) * sin(q / 2) / q + 2 * sin(q / 10) * cos(q / 3)) * exp(-t * q * q) * cos(q * x);
- return result;
- }
- void calculation() {
- double result = 0;
- fstream f;
- ///////////////// 2T
- f.open("C://Users//User//Documents//2T.txt", fstream::trunc | fstream::out);
- for (double j = 0; j < 1; j+= step_x){
- for (int i = 0; i < max_number; i++) {
- result += calculate(q_array[i], j, 2);
- }
- result += -2 + j;
- f << result << endl;
- result = 0;
- }
- f.close();
- /////////////////////////
- //////////////////////5T
- f.open("C://Users//User//Documents//5T.txt", fstream::trunc | fstream::out);
- for (double j = 0; j < 1; j += step_x) {
- for (int i = 0; i < max_number; i++) {
- result += calculate(q_array[i], j, 5);
- }
- result += -2 + j;
- f << result << endl;
- result = 0;
- }
- f.close();
- /////////////////////////
- //////////////////////l/3
- f.open("C://Users//User//Documents//l.txt", fstream::trunc | fstream::out);
- for (double j = 0; j < 5; j += step_t) {
- for (int i = 0; i < max_number; i++) {
- result += calculate(q_array[i], (double)1/3, j);
- }
- result += -2 + (double)1/3;
- f << result << endl;
- result = 0;
- }
- f.close();
- /////////////////////////
- //////////////////////T= 0
- f.open("C://Users//User//Documents//0.txt", fstream::trunc | fstream::out);
- for (double j = 0; j < 1; j += step_x) {
- for (int i = 0; i < max_number; i++) {
- result += calculate(q_array[i], j, 0);
- }
- result += -2 + j;
- f << result << endl;
- result = 0;
- }
- f.close();
- }
- int main() {
- finding_qk();
- calculation();
- fstream f;
- f.open("C://Users//User//Documents//step_x.txt", fstream::trunc | fstream::out);
- for (double i = 0; i < 1; i+=step_x) {
- f << i << endl;
- }
- f.close();
- f.open("C://Users//User//Documents//step_t.txt", fstream::trunc | fstream::out);
- for (double i = 0; i < 5; i += step_t) {
- f << i << endl;
- }
- f.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement