importnumpyasnpimportmatplotlib.pyplotasplt# ConstantsL=1r=L/2# Number of pointsnpts=51x=np.linspace(0,L,npts)# Define the piecewise functionf1=(1/4)*(5*(x/r)**4-3*(x/r)**5)z=(2*r-x)/rf2=-(1/4)*(5*z**4-3*z**5)+1f=np.where(x<=r,f1,f2)# Points and lines for plottingpts=np.array([[0,1],[1,0]])lines=np.array([[-1,1],[0,1],[0,0],[2,0]])z=np.flip(x)# Plottingplt.figure()plt.plot(z,f,label='Smooth Function')plt.plot(pts[:,0],pts[:,1],'o',label='Points')plt.plot(lines[:,0],lines[:,1])plt.legend()plt.show(block=False)# Data preparation for savingsmooth=np.column_stack((z,f))# Save data to filewithopen("indicator.dat","w")asf:np.savetxt(f,smooth,fmt='%f',header='z, f')f.write("\n\n")np.savetxt(f,pts,fmt='%f',header='x, y')f.write("\n\n")np.savetxt(f,lines,fmt='%f',header='x0, x1')