-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathheat_equation_1d.brainrot
50 lines (44 loc) · 1.4 KB
/
heat_equation_1d.brainrot
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
skibidi main {
rizz N = 50;
gigachad u[50];
gigachad u_new[50];
rizz i;
rizz t;
rizz timesteps = 100;
🚽 Initialize array
flex (i = 0; i < N; i = i + 1) {
edgy ((i > 16) && (i < 33)) {
u[i] = 100.0;
} amogus {
u[i] = 0.0;
}
}
🚽 Time evolution using just comparisons
flex (t = 0; t < timesteps; t = t + 1) {
edgy (t % 10 == 0) {
yapping("Timestep %d: ", t);
flex (i = 0; i < N; i = i + 1) {
yapping("%lf", u[i]);
}
yapping("");
}
🚽 Update interior points using only assignments
flex (i = 1; i < N-1; i = i + 1) {
edgy (u[i+1] > u[i]) {
u_new[i] = u[i] + 1.0; 🚽 If right neighbor is higher, increase slightly
} amogus edgy (u[i-1] > u[i]) {
u_new[i] = u[i] + 1.0; 🚽 If left neighbor is higher, increase slightly
} amogus edgy ((u[i-1] < u[i]) && (u[i+1] < u[i])) {
u_new[i] = u[i] - 1.0; 🚽 If both neighbors are lower, decrease slightly
} amogus {
u_new[i] = u[i]; 🚽 Otherwise keep same value
}
}
u_new[0] = 0.0;
u_new[N-1] = 0.0;
flex (i = 0; i < N; i = i + 1) {
u[i] = u_new[i];
}
}
bussin 0;
}