# %% Import of packages: import numpy as np import matplotlib.pyplot as plt # %% Def of objective function: def fun_f(x, L): A = (L/2 - x)*x f = -A return f # %% Model param: L = 40 # [m] # %% Calculating f(x) for a number of x values: x_lb = 0 x_ub = L/2 N_x = 100 x_array = np.linspace(x_lb, x_ub, N_x) f_array = fun_f(x_array, L) # Vectorized function call # %% Plotting f(x): plt.close('all') # Closes all figures before plotting plt.figure(num=1, figsize=(12, 9)) # Inches plt.plot(x_array, f_array, '.', label='f = -A') plt.legend() plt.xlabel('x [m]') plt.ylabel('[m2]') plt.grid() # plt.savefig('plot_square.pdf') plt.show()