import numpy as np import matplotlib.pyplot as plt # %% Parameters of uniform(): mu_n = 0 # deg C. Sub-index n for noise. sigma_n = 0.1 # deg C a = mu_n - np.sqrt(3)*sigma_n b = mu_n + np.sqrt(3)*sigma_n sample_size = 1 # %% Time settings: t_start = 0 # s t_stop = 5 # s ts = 0.05 # s t_array = np.arange(t_start, t_stop+ts, ts) # %% Preallocation of array for storing sim results: N = len(t_array) T_0 = 70 # Deg C T_array = np.zeros(N) + T_0 # %% For loop implementing iterative simulation: for k in range(0, N): temp_noise_k = np.random.uniform(a,b,sample_size)[0] T_k = T_0 + temp_noise_k T_array[k] = T_k # %% Plotting: plt.close('all') fig1 = plt.figure(num=1, figsize=(30/2.54, 24/2.54))#Inch # Plotting normal dist function: plt.plot(t_array, T_array, 'b-') plt.plot(t_array, T_array, 'bo') plt.plot(t_array, np.zeros(N) + T_0, 'g') plt.plot(t_array, np.zeros(N) + T_0 + a, '--r') plt.plot(t_array, np.zeros(N) + T_0 + b, '--r') plt.grid() plt.title('') plt.xlabel('t [s]') plt.ylabel('Deg C') plt.show() # plt.savefig('plot_temp_sim_with_noise.pdf')