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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| import plotly import math from plotly.graph_objs import Scatter, Layout
t1 = 0 t2 = 0 t3 = 0 t4 = 0 g = 9.81 c = 12.5 m = 68.1 delta1 = 0.6 delta2 = 1.2 delta3 = 2.4 vel = 0 vel1 = 0 vel2 = 0 vel3 = 0 vel4 = 0 Ti1 = [0] Ve1 = [0] Ti2 = [0] Ve2 = [0] Ti3 = [0] Ve3 = [0] Ti4 = [0] Ve4 = [0]
def velocity(vel, delta): value = vel + (g - c * vel / m) * delta return value
def realsol(t): Value = 53.44*(1-math.exp(1)**(-0.18355*t)) return Value
def Error1(): Err1 = (realsol(12) - Ve1[20])*100 / realsol(12) round(Err1, 1) return Err1
def Error2(): Err2 = (realsol(12) - Ve2[10])*100 / realsol(12) round(Err2, 1) return Err2
def Error3(): Err3 = (realsol(12) - Ve3[5])*100 / realsol(12) round(Err3, 1) return Err3
for a in range(0, 80): vel1 = velocity(vel1, delta1) t1 = t1 + delta1 T1 = round(t1, 1) VEL1 = round(vel1, 1) Ti1 = Ti1 + [T1] Ve1 = Ve1 + [VEL1]
for a in range(0, 40): vel2 = velocity(vel2, delta2) t2 = t2 + delta2 T2 = round(t2, 1) VEL2 = round(vel2, 1) Ti2 = Ti2 + [T2] Ve2 = Ve2 + [VEL2]
for a in range(0, 20): vel3 = velocity(vel3, delta3) t3 = t3 + delta3 T3 = round(t3, 1) VEL3 = round(vel3, 1) Ti3 = Ti3 + [T3] Ve3 = Ve3 + [VEL3]
for a in range(0, 4800): vel4 = realsol(t4) t4 = t4 + 0.01 T4 = round(t4, 1) VEL4 = round(vel4, 1) Ti4 = Ti4 + [T4] Ve4 = Ve4 + [VEL4]
plotly.offline.plot({ "data": [Scatter(x=Ti1, y=Ve1)], "layout": Layout(title="ODE 풀이, delta = 0.6") })
plotly.offline.plot({ "data": [Scatter(x=Ti2, y=Ve2)], "layout": Layout(title="ODE 풀이, delta = 1.2") })
plotly.offline.plot({ "data": [Scatter(x=Ti3, y=Ve3)], "layout": Layout(title="ODE 풀이, delta = 2.4") })
plotly.offline.plot({ "data": [Scatter(x=Ti4, y=Ve4)], "layout": Layout(title="ODE 풀이, realsol") })
print(Error1()) print(Error2()) print(Error3())
|