예제 #1
0
def calculateDiffusion(simulations,
                       getDistanceFromOrigin=getBallDistancesFromOrigin):
    squaredDistances = [
        squareList(getDistanceFromOrigin(simulation))
        for simulation in simulations
    ]
    maxTimes = max(
        [len(squaredDistance) for squaredDistance in squaredDistances])
    minTimes = min(
        [len(squaredDistance) for squaredDistance in squaredDistances])

    # Since time limit differs between multiple simulations, we repeat the last element for those shorter.
    # normalizedLists = []
    # for squaredDistance in squaredDistances:
    #   if len(squaredDistance) <= maxTimes:
    #     normalizedLists.append(squaredDistance + [squaredDistance[-1]]*(maxTimes - len(squaredDistance)))

    # Since time limit differs between multiple simulations, we keep their shortest length
    print(minTimes)
    normalizedLists = []
    for squaredDistance in squaredDistances:
        normalizedLists.append(squaredDistance[:minTimes])

    # Since time limit differs between multiple simulations, we average those that exist for a specific step.
    # normalizedLists = []
    # for squaredDistance in squaredDistances:
    #   if len(squaredDistance) <= maxTimes:
    #     normalizedLists.append(squaredDistance + [numpy.nan]*(maxTimes - len(squaredDistance)))

    averageSquaredDistances = averageLists(normalizedLists)[(minTimes) // 2:]
    deviations = stdevLists(normalizedLists)[(minTimes) // 2:]

    diffusion, b = linearRegression(averageSquaredDistances)
    return diffusion, b, averageSquaredDistances, deviations
예제 #2
0
def tp5_e1b(simulations):
    kineticEnergies = [calculateKineticEnergy(simulation) for simulation in simulations]
    kineticEnergy = averageLists(kineticEnergies)
    kineticErrs = stdevLists(kineticEnergies)
    dt = 0.005 # seconds
    fig, ax = plt.subplots()
    # ax.set_yscale('log')
    ax.set_ylabel('Energía cinética [J]')
    ax.set_xlabel('Tiempo [s]')
    fig.tight_layout()
    ax.plot([x * dt for x in range(len(kineticEnergy))], kineticEnergy, 'o-', markersize=3)
    saveFig(fig, '1_1b')
예제 #3
0
def calculateExitsValues(qs):
    lastThird = qs[-len(qs) // 3:]
    avg = averageLists(lastThird)
    err = stdevLists(lastThird)
    return avg, err