Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"//vs2010
- #include <iostream>
- #include <complex>
- #include <cassert>
- #include <vector>
- #include <conio.h>
- #include <windows.h>
- #include "decimal.h"
- #include "gnuplot_i.hpp"
- using namespace std;
- using namespace dec;
- #define M_PI 3.14159265358979323846
- #define dec10 decimal<10>
- #define dabs(a) fabs((a).getAsDouble())
- #define FOUT
- #define cyrillic setlocale(LC_CTYPE, "rus")
- inline string dtos(double d){ostringstream strs; strs << d; return strs.str();}
- void wait(){
- FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE));
- #ifndef FOUT
- cout << endl << "Press any key to continue..." << endl;
- #endif
- _getch();
- }
- int main(){
- cyrillic;
- freopen("input.txt","r",stdin);
- freopen("output.txt","w",stdout);
- vector<dec10> x;
- dec10 tmp;
- while(cin >> tmp){
- x.push_back(tmp);
- }
- int n = x.size();
- vector<dec10> dft(n + 1);
- for(int i = 0 ; i < n ; ++i){
- dec10 real = dec10(0);
- for(int j = 0 ; j < n ; ++j){
- dec10 angle = dec10((2 * M_PI * i * j) / n);
- real += x[j] * dec10(cos(angle.getAsDouble()));
- }
- dft[i] = real;
- }
- vector<pair<dec10 , dec10>> mx; //{coordinate , value}
- for(int i = 0 ; i < n / 2 ; ++i){
- if(!i){
- if(dft[i] > dft[i + 1]){
- mx.push_back(make_pair(i * 0.01 , dft[i]));
- }
- }else{
- if(dft[i] > dft[i + 1] && dft[i] > dft[i - 1]){
- mx.push_back(make_pair(i * 0.01 , dft[i]));
- }
- }
- }
- for(int i = 0 ; i < mx.size() ; ++i){
- cout << mx[i].second << " ";
- }
- reverse(dft.begin() , dft.end());
- dft.pop_back();
- reverse(dft.begin() , dft.end());
- string to_plot = "[0:5] ";
- int cur = 0;
- for(double i = 0. ; fabs(i - 5.00) > 1e-3 ; i += 0.01){
- if(fabs(i - 4.99) <= 1e-3){
- to_plot += dtos(dabs(dft[cur]));
- break;
- }
- to_plot += "x>=";
- to_plot += dtos(i);
- to_plot += "&x<";
- to_plot += dtos(i + 0.01);
- to_plot += "?";
- to_plot += dtos(dabs(dft[cur++]));
- to_plot += ":";
- }
- Gnuplot gnu("lines");
- gnu.plot_equation(to_plot,"dft");
- wait();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment