Ejemplo n.º 1
0
def make_initial_conditions(system, displacement, low):
    """
    A FUNCTION THAT CREATES THE INITIAL CONDITIONS FOR THE SEARCH OF THE
    COMMUTATION CURVE IN A DETERMINED SYSTEM. TAKES AS INPUT THE SYSTEM THAT
    IS GOING TO BE ANALYZED, THE displacement TO THE RIGHT, AND HOW FAR low THE
    LINE SEGMENT IS GOING TO GO.
    """
    C = sir.CurveSegment(system.sbar, system.imax, 0, system, 1)
    C.s = C.s + displacement
    s_inter, i_inter = C._curve_sol(low)
    C = sir.CurveSegment(system.sbar, system.imax, 0, system, s_inter)
    C.s = C.s + displacement
    s0 = np.linspace(C.s[-1], 1)
    i0 = np.array([i_inter] * len(s0))
    s0 = np.concatenate((C.s, s0))
    i0 = np.concatenate((C.i, i0))
    return s0, i0
Ejemplo n.º 2
0
def tra(s_c, point, system):
    """
    A FUNCTION THAT CALCULATES THE TIME OF THE TRAJECTORY BY A GIVEN
    CONMUTATION POINT s.
    """
    try:
        s_c = s_c[0]
    except:
        pass
        #print("Input is already a float.")
    #print("The given conmutation point is: {}".format(s_c))
    u0_curve = sir.CurveSegment(point.s0, point.i0, 0, system)
    sc, ic = u0_curve._curve_sol(system.imax)
    #print("The intersection point is: {}".format(sc))
    if s_c >= sc:
        #print("I'ma do it with only two thingamajigs.")
        Tu = sir.CurveSegment(point.s0, point.i0, 0, system, s_c)
        Tu.get_time()
        i_c = system._curve(s_c, point.s0, point.i0, 0)
        Tc = sir.CurveSegment(s_c, i_c, system.umax, system)
        send, iend = Tc.curve_intersection(system.tau)
        Tc = sir.CurveSegment(s_c, i_c, system.umax, system, send)
        Tc.get_time()
        #print("Tu: {}".format(Tu.time))
        #print("Tc: {}".format(Tc.time))
        #print(Tu.time + Tc.time)
        return sir.Trajectory(Tu, Tc)
    else:
        #print("I'ma have to do it with three thingamajigs.")
        Tu = sir.CurveSegment(point.s0, point.i0, 0, system, sc)
        Tu.get_time()
        Ts = sir.LineSegment(sc, s_c, system)
        Ts.get_time()
        Tc = sir.CurveSegment(s_c, system.imax, system.umax, system)
        send, iend = Tc.curve_intersection(system.tau)
        Tc = sir.CurveSegment(s_c, system.imax, system.umax, system, send)
        Tc.get_time()
        #print("Tu: {}".format(Tu.time))
        #print("Ts: {}".format(Ts.time))
        #print("Tc: {}".format(Tc.time))
        #print(Tu.time + Ts.time + Tc.time)
        return sir.Trajectory(Tu, Ts, Tc)
Ejemplo n.º 3
0
    return f


def fun2(x):
    f = 1 / (x * fun(x))
    return f


#%%
A = Test(0.6)
print(A)
print(A.x)
print(A.get_time(0.6, 0.5))

imax = 0.1
umax = 0.5
gamma = 0.2
beta = 0.5
B = sir.SIR()
B.set_params([imax, umax, gamma, beta], flag="bg")
B._find_tau()
T = B.tau
T.get_time(2, 1)

L = sir.CurveSegment(0.6, 0.08, umax, B, 0.5)
L.get_time(0.6, 0.5)
print(L.time)

i = scipy.integrate.quad(fun2, 0.6, 0.5)
print(-i[0] / ((1 - 0.5) * 0.5))
Ejemplo n.º 4
0
# SET HOW FAR TO THE RIGHT THE REFERENCE CURVE BASED ON SIR.tau WILL BE MOVED.
displacement = 0.001
# SET HOW FAR LOW THE CURVE SIR.tau WILL GO.
i_low = 0.0005

#%%
# CREATE SYSTEM, SET PARAMETERS, AND FIND CURVES tau, phi ET CETERA.
A = sir.SIR()
A.set_params([imax, umax, gamma, beta], flag="bg")
A._find_curves()

# CREATE A CURVE THAT IS A CLONE OF A.tau AND DISPLACE IT TO THE RIGHT BY
# displacement UNITS. USE THIS CURVE AND A LINSPACE AT I = i_low TO CREATE ALL
# INITIAL CONDITIONS, s0 AND i0.
C = sir.CurveSegment(A.sbar, A.imax, 0, A, 1)
C.s = C.s + displacement
s_inter, i_inter = C._curve_sol(i_low)
C = sir.CurveSegment(A.sbar, A.imax, 0, A, s_inter)
C.s = C.s + displacement
s0 = np.linspace(C.s[-1], 1)
i0 = np.array([i_inter] * len(s0))
s0 = np.concatenate((C.s, s0))
i0 = np.concatenate((C.i, i0))

# A PLOT TO SEE IF ALL IS ALRIGHT.
fig, ax = plt.subplots()
ax.set_xlabel(r"$S$")
ax.set_ylabel(r"$I$")
ax.set_xlim(A.sbar, 1)
ax.set_ylim(0, A.imax * 1.1)
Ejemplo n.º 5
0

#%%
imax = 0.1
umax = 0.5
gamma = 0.2
beta = 0.5

displacement = 0.01
i_low = 0.0005

#%%
A = sir.SIR()
A.set_params([imax, umax, gamma, beta], flag="bg")

C = sir.CurveSegment(A.sbar, A.imax, 0, A, 1)
C.s = C.s + displacement
s_inter, i_inter = C._curve_sol(i_low)
C = sir.CurveSegment(A.sbar, A.imax, 0, A, s_inter)
C.s = C.s + displacement
s0 = np.linspace(C.s[-1], 1)
i0 = np.array([i_inter] * len(s0))
s0 = np.concatenate((C.s, s0))
i0 = np.concatenate((C.i, i0))

fig, ax = plt.subplots()
ax.set_xlim(A.sbar, 1)
ax.set_ylim(0, A.imax * 1.1)
ax.plot(A.tau.s, A.tau.i, "r-")
ax.plot(s0, i0, "b-")