1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import os import matplotlib.pyplot as plt import numpy as np os.chdir('/home/vg/Downloads/projects/ex15') os.getcwd() #define model parameters x=np.linspace(-2,2,1000) #examples of nonlinear functions f1=x**2-x-1 f2=x**3-3*np.sin(x) f3=np.exp(x)-2 f4=1-x**2+np.sin(50/(1+x**2)) fig,axes=plt.subplots(1,4,figsize=(12,3),sharey=True) for n,f in enumerate([f1,f2,f3,f4]): axes[n].plot(x,f,lw=1.5) axes[n].axhline(0,ls=':',color='k') axes[n].set_ylim(-5,5) axes[n].set_xticks([-2,-1,0,1,2]) axes[n].set_xlabel(r'$x$',fontsize=18) axes[0].set_ylabel(r'$f(x)$',fontsize=18) titles=[r'$f(x)=x^2-x-1$',r'$f(x)=x^3-3\sin(x)$',r'$f(x)=\exp(x)-2$', r'$f(x)=\sin\left(50/(1+x^2)\right)+1-x^2$'] for n,title in enumerate(titles): axes[n].set_title(title) plt.savefig("example15.png", dpi=100) plt.show() plt.close() <img class=" wp-image-94 aligncenter" src="https://gantovnik.com/bio-tips/wp-content/uploads/2018/12/example15.png" alt="example15" width="548" height="137" /> |
Recent Comments