Last active
October 22, 2018 18:03
-
-
Save dermesser/2d742669547504ab38c61ecf21a17fc2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Experimentalphysik I 2018/19: Schiefer Wurf. | |
// Gruppe 7 | |
// | |
// (c) 2018 Lewin Bormann | |
package main | |
import ( | |
"flag" | |
"fmt" | |
"math" | |
) | |
var ( | |
h0 = flag.Float64("h0", 0, "h0") | |
v0 = flag.Float64("v0", 10, "v0") | |
beta = flag.Float64("beta", 30, "beta") | |
t = flag.Float64("t", 0.1, "delta-t") | |
g = flag.Float64("g", 9.81, "g") | |
) | |
type state struct { | |
t float64 | |
h, x float64 | |
v_vert, v_horiz float64 | |
} | |
func iterate(s state, delta float64) state { | |
next := s | |
next.t += delta | |
next.h += delta * s.v_vert | |
next.x += delta * s.v_horiz | |
next.v_vert -= delta * *g | |
next.v_horiz = s.v_horiz | |
return next | |
} | |
func print(s state) { | |
fmt.Printf("%.3f\t%.3f\t%.3f\t%.3f\t%.3f\n", s.t, s.x, s.h, s.v_horiz, s.v_vert) | |
} | |
func main() { | |
flag.Parse() | |
s := state{ | |
t: 0, | |
h: *h0, | |
x: 0, | |
v_vert: math.Sin((*beta/180)*math.Pi) * *v0, | |
v_horiz: math.Cos((*beta/180)*math.Pi) * *v0, | |
} | |
for s.h >= 0 { | |
print(s) | |
s = iterate(s, *t) | |
} | |
print(s) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment