RTXI  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
sd_theor.cpp
Go to the documentation of this file.
1 //
2 // File = sd_filt.cpp
3 //
4 
5 #include <fstream>
6 #include <math.h>
7 #include <iostream>
8 
9 #include "sd_theor.h"
10 #include "misdefs.h"
11 
12 using namespace std;
13 
14 #ifdef _DEBUG
15 extern std::ofstream DebugFile;
16 #endif
17 
18 void
19 SteepestDescentTheoretic(double start_pt_0, double start_pt_1, double mu,
20  int num_pts, double min_dist)
21 {
22  int n;
23  double w0, w1, old_w0, old_w1, grad_0, grad_1;
24  double dist, radius, angle, deg_per_rad;
25  std::cout << "in SteepestDescentTheoretic" << std::endl;
26  ofstream out_file("sd_traj.txt", ios::out);
27 
28  deg_per_rad = 180.0 / PI;
29  w0 = start_pt_0;
30  w1 = start_pt_1;
31  old_w0 = w0;
32  old_w1 = w1;
33  out_file << "0, " << old_w0 << ", " << old_w1 << std::endl;
34 
35  for (n = 1; n < num_pts; n++) {
36  grad_0 = 2.0 * (w0 + (w1 - 1.0) / 3.0);
37  grad_1 = 2.0 * w1 + (2.0 * w0 / 3.0) + 1.2;
38  w0 -= mu * grad_0;
39  w1 -= mu * grad_1;
40  dist = sqrt((w0 - old_w0) * (w0 - old_w0) + (w1 - old_w1) * (w1 - old_w1));
41  if (dist < min_dist)
42  continue;
43  radius = sqrt(w0 * w0 + w1 * w1);
44  angle = deg_per_rad * atan2(w1, w0);
45  out_file << n << ", " << w0 << ", " << w1 << std::endl;
46  old_w0 = w0;
47  old_w1 = w1;
48  }
49  out_file.close();
50 }
#define PI
Definition: misdefs.h:9
complex sqrt(const complex _z)
Definition: complex.h:148
void SteepestDescentTheoretic(double start_pt_0, double start_pt_1, double mu, int num_pts, double min_dist)
Definition: sd_theor.cpp:19
std::ofstream DebugFile