Creating a piecewise function that recurs indefinitely with a constant that needs to be solved each switch

29 views Asked by At

Okay, I know the title is a mouthful, but it is easier to express with functions.

I need these functions to repeat for t up to very large numbers (i.e. t = 36,000,000) and each function needs to be continuous. Because of that, each C needs to be recalculated at the end of each piece of the function. I know how to do the first 1200 seconds no problem, but making the function continue several times recalculating each C is what is stumping me.

for this problem,

Mn55(0) = 0
Mn56(0) = 0
p = 1E13
u = 1.10872E-05
lambda = 0.26659



if t%1200 = 1:

    Mn55(t) = -C1*e^(-ptu) + q/pu 
else:

    Mn55(t) = q*t + C2



if t%1200 = 1:

    Mn56(t) = C3*e^(-lambda*t) + phi*t*u*Mn55(t)/lambda - phi*u*Mn55(t)/lambda^2
else:
    
    Mn56(t) = C4*e^(lambda*t)



For further reference, these are the differential equations governing each variable.:




if t%1200 = 1:

    dMn55 = -u*phi*Mn55+Q   
else: 

    dMn55 = Q


if t%1200 = 1:

        dMn56/dt = u*phi*Mn55(t) - lambda*Mn56(t)
else:

        dMn56/dt = - lambda*Mn56(t)

A solution using either the differential equation or the solved analytical solutions are both valid. I just need to be able to create a plot of both equations Mn55(t) and Mn56(t).

0

There are 0 answers