fromphysipyimportm,units,s,setup_matplotlibsetup_matplotlib()importnumpyasnpimportmatplotlib.pyplotaspltPolynomial=np.polynomial.Polynomial# Radius of the spherical tank in mR=1.5*m# Flow rate out of the tank, m^3.s-1F=2.e-4*m**3/s# Total volume of the tankV0=4/3*np.pi*R**3# Total time taken for the tank to emptyT=V0/F# coefficients of the quadratic and cubic terms# of p(h), the polynomial to be solved for hc2,c3=np.pi*R,-np.pi/3N=100# array of N time points between 0 and T inclusivetime=np.linspace(0*s,T,N)# create the corresponding array of heights h(t)h=np.zeros(N)fori,tinenumerate(time):c0=F*t-V0p=Polynomial([c0.value,0,c2.value,c3])# find the three roots to this polynomialroots=p.roots()# we want the one root for which 0 <= h <= 2Rh[i]=roots[(0<=roots)&(roots<=2*R.value)][0]h=h*mfig,ax=plt.subplots()ax.plot(time,h,'o')ax.set_xlabel("Time ("+str(ax.xaxis.get_label().get_text())+")")ax.set_ylabel("Height in tank ("+str(ax.yaxis.get_label().get_text())+")")plt.show()