#### Simulation: #### N_sim = T_horiz # Time vector k_range = np.arange(N_sim) k_range_x = np.arange(N_sim + 1) # State variables E = np.zeros(N_sim + 1) E[0] = E_rated / 2 # Control variables P_sto = np.zeros(N_sim) # Simulation loop: for k in k_range: # Control computation: P_sto_law = dpsolv.interp_on_state(pol_sto[k]) P_sto[k] = P_sto_law(E[k]) # State evolution: E[k + 1], = sto_sys.dyn(k, E[k], P_sto[k]) # Compute state variables derivatives: E_full = np.ma.array(E, mask=(E < E_rated * 0.9999)) E_empty = np.ma.array(E, mask=(E > E_rated * 0.0001)) # Deviation from commitment: P_grid = P_prod_data - P_sto P_grid_l2 = np.sqrt(np.mean(P_grid**2)) print('RMS deviation: {:.4f}'.format(P_grid_l2)) ### Plot: fig, ax = plt.subplots(2, 1, sharex=True)
N_sim = T_horiz # Time vector k_range = np.arange(N_sim) k_range_x= np.arange(N_sim+1) # State variables E = np.zeros(N_sim+1) E[0] = p['E_rated']/2 # Control variables P_sto = np.zeros(N_sim) # Simulation loop: for k in k_range: # Control computation: P_sto_law = dpsolv.interp_on_state(pol_sto[k]) P_sto[k] = P_sto_law(E[k]) # State evolution: E[k+1], = sto_sys.dyn(k, E[k], P_sto[k]) # Compute state variables derivatives: E_full = np.ma.array(E, mask = (E<p['E_rated']*0.9999)) E_empty = np.ma.array(E, mask = (E>p['E_rated']*0.0001)) # Deviation from commitment: P_dev = p['P_req_data'] - P_sto P_req_l2 = np.sqrt(np.mean(p['P_req_data']**2)) P_dev_l2 = np.sqrt(np.mean(P_dev**2)) print('input RMS deviation: {:.4f}'.format(P_req_l2)) print('output RMS deviation: {:.4f}'.format(P_dev_l2))