60 lines
1.3 KiB
Python
60 lines
1.3 KiB
Python
import numpy as np
|
|
import pandas as pd
|
|
import random, os
|
|
|
|
def valores_objetivo(archivo, material):
|
|
carga = pd.read_excel(archivo, sheet_name='carga', engine='openpyxl').dropna()
|
|
|
|
E = np.mean(carga.loc[carga['material'] == material, ['V1', 'V2']].values, axis=1)
|
|
I = np.mean(carga.loc[carga['material'] == material, ['I1', 'I2']].values, axis=1)
|
|
f = np.array(carga['f'][carga['material'] == material])
|
|
|
|
return E, I, f
|
|
|
|
|
|
def generar_curva(offset):
|
|
muVacio = 4 * np.pi * 1e-7
|
|
|
|
hPos = np.arange(1,5001,1)
|
|
hNeg = np.arange(-5000,0,1)
|
|
|
|
bPos = muVacio*hPos + offset
|
|
bNeg = muVacio*hNeg - offset
|
|
|
|
h = np.concatenate((hNeg, hPos))
|
|
b = np.concatenate((bNeg, bPos))
|
|
|
|
datos = np.column_stack((h,b))
|
|
np.savetxt('curva.csv', datos, delimiter=',')
|
|
|
|
|
|
def logica_offset(offset, error, errorObjetivo):
|
|
'''
|
|
Coge el offset, error actual y lo analiza.
|
|
|
|
devuelve flag y offset nuevo
|
|
|
|
si se cumple la condicion devuelve
|
|
un True y None para offset
|
|
|
|
'''
|
|
|
|
limSup = 1 + errorObjetivo
|
|
limInf = 1 - errorObjetivo
|
|
|
|
delta = random.random()/100
|
|
|
|
if error <= limSup and error >= limInf: return True, None
|
|
|
|
if error > 1: offset = offset - delta
|
|
elif error < 1: offset = offset + delta
|
|
|
|
return False, offset
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|