Skip to content

Commit 2927ab0

Browse files
committed
adding new java implementation for verlet and some images to FFT
1 parent 00fee33 commit 2927ab0

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

chapters/computational_mathematics/cooley_tukey.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ Where $$F(\xi)$$ represents a function in frequency space and $$\xi$$ represents
4343

4444
If we take a sinusoidal function like $$\sin(\omega t)$$ or $$\cos(\omega t)$$, we find a curve that goes from $$\pm1$$, shown in FIGURE1a. Both of these curves can be described by their corresponding frequencies, $$\omega$$. So, instead of representing these curves as seen in FIGURE1a, We could instead describe them as shown in FIGURE1b. Here, FIGURE1a is in real space and FIGURE1b is in frequency space.
4545

46+
![Complicated Sinusoidal Function](sinusoid.png)
47+
48+
*FIGURE1a: Complicated Sinusoidal Function*
49+
50+
![FFT of FIGURE1a](fft.png)
51+
52+
*FIGURE1b: abs(fft(FIGURE1a))*
53+
4654
Now, how does this relate to the transformations above? Well, the easiest way is to substitute in the following relation:
4755

4856
$$e^{2 \pi i \theta} = \cos(2 \pi \theta) + i \sin(2 \pi \theta)$$
4.92 KB
Loading
7.68 KB
Loading

chapters/computational_physics/verlet.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,74 @@ int main(){
181181
}
182182

183183
```
184+
185+
#### Java
186+
```java
187+
188+
// Submitted by lolatomroflsinnlos
189+
// Thanks a lot!
190+
static void verlet(double pos, double acc, double dt){
191+
192+
// Note that we are using a temp variable for the previous position
193+
double prev_pos, temp_pos, time;
194+
prev_pos = pos;
195+
time = 0;
196+
197+
while (pos > 0){
198+
time += dt;
199+
temp_pos = pos;
200+
pos = pos*2 - prev_pos + acc * dt * dt;
201+
prev_pos = temp_pos;
202+
}
203+
204+
System.out.println(time);
205+
206+
}
207+
208+
// Simple function for stormer-verlet
209+
static void stormer_verlet(double pos, double acc, double dt){
210+
211+
// Note that we are using a temp variable for the previous position
212+
double prev_pos, temp_pos, time, vel;
213+
prev_pos = pos;
214+
vel = 0;
215+
time = 0;
216+
while (pos > 0){
217+
time += dt;
218+
temp_pos = pos;
219+
pos = pos*2 - prev_pos + acc * dt * dt;
220+
prev_pos = temp_pos;
221+
222+
// The acceleration is constant, so the velocity is straightforward
223+
vel += acc*dt;
224+
}
225+
226+
System.out.println(time);
227+
228+
}
229+
230+
// Simple function for velocity-verlet
231+
static void velocity_verlet(double pos, double acc, double dt){
232+
233+
// Note that we are using a temp variable for the previous position
234+
double time, vel;
235+
vel = 0;
236+
time = 0;
237+
while (pos > 0){
238+
time += dt;
239+
pos += vel*dt + 0.5*acc * dt * dt;
240+
vel += acc*dt;
241+
}
242+
243+
System.out.println(time);
244+
245+
}
246+
247+
public static void main(String[] args) {
248+
249+
verlet(5.0, -10, 0.01);
250+
stormer_verlet(5.0, -10, 0.01);
251+
velocity_verlet(5.0, -10, 0.01);
252+
253+
}
254+
```

0 commit comments

Comments
 (0)