-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuperposition_Waves.hpp
More file actions
68 lines (59 loc) · 2.11 KB
/
Superposition_Waves.hpp
File metadata and controls
68 lines (59 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
class kick{
private:
int i,n;
float am1,am2,t1,t2,p1,p2,t,*a1,*a2,*a3;
public:
void up(){
std::cout<<"enter the no.of cycles of the loop:::\n";
std::cin>>n;
std::cout<<"plz enter the amplitude , inverse of T , phase of wave 1 respectively :::\n";
std::cin>>am1>>t1>>p1;
std::cout<<"plz enter the amplitude , inverse of T , phase of wave 2 respectively :::\n";
std::cin>>am2>>t2>>p2;
std::cout<<"you entered the following amplitude t inverse phase\n";
std::cout<<"wave 1"<<" "<<am1<<" "<<t1<<" "<<p1<<"\n";
std::cout<<"wave 2"<<" "<<am2<<" "<<t2<<" "<<p2<<"\n";
}
void at_ease(){
a1 = new float[n];
a2 = new float[n]; // allocating array size
a3 = new float[n];
t=0.0;
p1 = (4*atan(1)/180.0)*p1; //
p2 = (4*atan(1)/180.0)*p2; //conversions
t1 = (8*atan(1)/t1); //
t2 = (8*atan(1)/t2); //
for(i=0;i<n;i++){
a1[i] = am1*sin(t1*t + p1) ;
a2[i] = am2*sin(t2*t + p2) ;
a3[i] = a1[i] + a2[i];
t = t + 0.1 ;
}
}
void still(){
std::ofstream outfl("supp.dat");
t=0.0;
for(i=0;i<n;i++){
outfl<<t<<" "<<a1[i]<<" "<<a2[i]<<" "<<a3[i]<<std::endl;
t = t + 0.1;
}
outfl.close();
// Important if building for both Unix and Windows OS
// Plot the data using gnuplot
#ifdef _WIN32
FILE* gnuplotPipe = _popen("gnuplot -persistent", "w");
#else
FILE* gnuplotPipe = popen("gnuplot -persistent", "w");
#endif
if (!gnuplotPipe) {
std::cerr << "Error opening pipe to gnuplot" << std::endl;
return;
}
fprintf(gnuplotPipe, "set title 'Superposition of Waves'\n");
fprintf(gnuplotPipe, "set xlabel 'Time'\n");
fprintf(gnuplotPipe, "set ylabel 'Amplitude'\n");
fprintf(gnuplotPipe, "plot 'supp.dat' using 1:2 with lines title 'Wave_1'\n");
fprintf(gnuplotPipe, "replot 'supp.dat' using 1:3 with lines title 'Wave_2'\n");
fprintf(gnuplotPipe, "replot 'supp.dat' using 1:4 with lines title 'Resultant'\n");
}
};