Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- T = 100
- h = 0.01
- a=1.5 #a ma być >0!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11
- y_max=70
- temp=22
- y_min=10
- M=3
- #schemat Eulera: x = x + h * (f)
- t = np.arange(0,T,h)
- x = np.ones(t.size)
- e = np.ones(t.size)
- u = np.zeros(t.size)
- x[0]=1
- e[0]=temp-x[0]
- for i in range(t.size - 1):
- e[i+1] = temp-x[i]
- print(e[i])
- if e[i+1]>M:
- u[i+1]=y_max
- elif e[i+1]<-M:
- u[i+1]=y_min
- elif e[i+1]>=-M or e[i+1]<M:
- u[i+1]=temp
- #x[i + 1] = x[i] + h * (a* x[i] + u[i])
- x[i + 1] = x[i] + h * ((u[i]-x[i])/a)
- plt.subplot(311)
- plt.plot(t, x, label='x')
- plt.hlines(temp,0, T,'r', 'dashed') # temp, rysuj od 0, do T, red, dashed
- plt.legend(loc='upper right')
- plt.xlabel('t')
- plt.ylabel('x')
- #plt.axis([40, 47, y_min, y_max])
- plt.axis([0, 10, temp-2, temp+2])
- #plt.ylim([0, 7])
- plt.subplot(312)
- plt.plot(t, e, label='e')
- plt.legend(loc='upper right')
- plt.xlabel('t')
- plt.ylabel('e')
- plt.hlines(0,0, T,'r', 'dashed')
- plt.axis([0, 100, -10, 5])
- plt.subplot(313)
- plt.plot(t, u, label='u')
- plt.legend(loc='upper right')
- plt.xlabel('t')
- plt.ylabel('u')
- plt.axis([0, 100, y_min-5, y_max+5])
- plt.show()
- #histereza, wytłumaczenie jak działa
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement