Exemplo n.º 1
0
import harmonic_oscillator as harm 
import matplotlib.pyplot as plt
import numpy as np

h1 = harm.HarmonicOscillator()

def apsolutna_pogreska():
    lista_delta_t = list(np.linspace(0.01 ,0.11 , 50))
    apsolutna_pogreska = []

    for delta_t in lista_delta_t:
        h1.init(0.1 ,2 ,0.2 ,0.1 ,delta_t)  
        greska = (abs(h1.period() - h1.period_analiticki()) / h1.period_analiticki()) * 100
        apsolutna_pogreska.append(greska)

    plt.plot(lista_delta_t, apsolutna_pogreska)
    plt.show()

apsolutna_pogreska()

Exemplo n.º 2
0
import harmonic_oscillator as ho

h1=ho.HarmonicOscillator(10,0.1,0.3,0)
h1.period_titr(0.1,5)
h1.reset()
h1=ho.HarmonicOscillator(10,0.1,0.3,0)
h1.period_titr(0.01,5)
h1.reset()
h1=ho.HarmonicOscillator(10,0.1,0.3,0)
h1.period_titr(0.001,5)
h1.analit_period()


Exemplo n.º 3
0
import matplotlib.pyplot as plt
import harmonic_oscillator as ho

h1 = ho.HarmonicOscillator(0, 0, 0, 0, 0)
h1.__init__(0.001, 1, 5, 10, 0)
h1.oscillate(25)
h1.plot_trajectory()
#print(h1.t)
plt.clf()

h1.__init__(0.001, 1, 5, 10, 0)
h1.oscillate(25)
plt.scatter(h1.t, h1.x, s=2, c="b", label="dt = 0.001")

h1.__init__(0.01, 1, 5, 10, 0)
h1.oscillate(25)
plt.scatter(h1.t, h1.x, s=4, c="g", label="dt = 0.01")

h1.__init__(0.5, 1, 5, 10, 0)
h1.oscillate(25)
plt.scatter(h1.t, h1.x, s=6, c="orange", label="dt = 0.05")

h1.__init__(0.01, 1, 5, 10, 0)
h1.analitic(25)
plt.plot(h1.t, h1.x, c="r", label="analitic")

plt.xlabel("t [s]")
plt.ylabel("x [m]")
plt.title("PRECIZNOST")
plt.legend(loc="lower right")
plt.show()
Exemplo n.º 4
0
import harmonic_oscillator as h_o
import matplotlib.pyplot as plt
import numpy as np

h_1 = h_o.HarmonicOscillator()


def preciznost():
    dt_lista = list(np.linspace(0.01, 0.11, 50))
    num_period = []
    a_period = []

    for dt in dt_lista:
        h_1.init(0.1, 5, 0, 0.5, dt)  #(m,k,v0,A,dt)
        num_period.append(h_1.period())
        a_period.append(h_1.period_analitic())
        h_1.reset()

    plt.plot(dt_lista, a_period, label="analiticki period")
    plt.scatter(dt_lista,
                num_period,
                s=3,
                c="orange",
                label="numericki period")
    plt.xlabel("dt [s]")
    plt.ylabel("T [s]")
    plt.title("Preciznost numerickog racunanja perioda")
    plt.legend(loc="lower right")
    plt.show()

Exemplo n.º 5
0
import harmonic_oscillator as ho

h1 = ho.HarmonicOscillator()

h1.init(0.1, 5, 0, 0.5, 0.001)  #(m,k,v0,A,dt)
print("Period titranja iznosi: {:.2f}".format(h1.period()))
print("Analiticki period titranja iznosi: {:.2f}".format(h1.period_analitic()))

#h1.period()
Exemplo n.º 6
0
import matplotlib.pyplot as plt
import harmonic_oscillator as ho

list_dt = []
list_err = []
dt = 0.0
N = 100

for i in range(N):
    dt += 0.01
    list_dt.append(dt)
    h1 = ho.HarmonicOscillator(0.1, 10, 0.3, 0, dt)
    error = abs(h1.numeric() - h1.analytic()) / h1.numeric() * 100
    list_err.append(error)

plt.plot(list_dt, list_err)
plt.ylabel("absolute relative error [%]")
plt.xlabel("dt [s]")
plt.title("Absolute relative error")
plt.show()