import numpy as np import matplotlib.pyplot as plt x = np.arange(0,12,0.01) y = np.sin(x) plt.plot(x,y) k = np.diff(y)/np.diff(x) plt.grid() plt.plot(x[:-1],k)
x = np.arange(0,1,0.001) y = np.exp(x) plt.plot(x,y,'ro') k = np.diff(y)/np.diff(x) plt.plot(x[1:],k,'b')
import numpy as np import matplotlib.pyplot as plt x = np.arange(-5.2,-0.9,0.01) y = x**5+15*x**4+85*x**3+225*x**2+274*x+120 j = np.heaviside(y,0) k = np.abs(np.diff(j)) plt.plot(x,y,'black') plt.plot(x[1:],k,'r') vec = np.argwhere(k==1) print(x[vec])
import numpy as np import matplotlib.pyplot as plt x = np.arange(-5.2,-0.9,0.01) y = x**5+15*x**4+85*x**3+225*x**2+274*x+120 a = np.diff(y)/np.diff(x) j = np.heaviside(a,0) k = np.abs(np.diff(j)) plt.plot(x,y,'black') plt.plot(x[2:],k,'r') vec = np.argwhere(k==1) print(x[vec])
import numpy as np import matplotlib.pyplot as plt step = 0.1 x = np.arange(-1,1,step) y = np.arange(-1,1,step) for i in x: for j in y: plt.plot(i,j,'o')
import numpy as np import matplotlib.pyplot as plt step=0.005 x=np.arange(-1,1,step) y=np.arange(-1,1,step) def dist(x,y): return np.sqrt(x**2+y**2) z=np.zeros([len(x),len(y)]) x0,y0 = -0.7269,0.1889 for j in range(len(x)): for k in range(len(y)): counter=0 px,py=x[j],y[k] while (dist(px,py)<2 and counter< 500): p1=px*px-py*py p2=2*px*py px,py=p1+x0,p2+y0 counter+=1 z[j,k]=counter plt.figure(figsize=(10,10)) plt.imshow(z); plt.colorbar();
import numpy as np import matplotlib.pyplot as plt r1 = np.random.rand(1000)*1 r12 = np.random.rand(1000)*1+0.8 r2 = np.random.rand(1000)*1+2 r3 = np.random.rand(1000)*1+3 r4 = np.random.rand(1000)*1+4 a1 = np.random.rand(1000)*6.28 a2 = np.random.rand(1000)*6.28 a3 = np.random.rand(1000)*6.28 a4 = np.random.rand(1000)*6.28 plt.plot(r1*np.cos(a1),r1*np.sin(a1),'ro') plt.plot(r2*np.cos(a2),r2*np.sin(a2),'go') plt.plot(r3*np.cos(a3),r3*np.sin(a3),'bo') plt.plot(r4*np.cos(a4),r4*np.sin(a4),'mo') plt.plot(r12*np.cos(a4),r12*np.sin(a4),'ro')
import numpy as np import matplotlib.pyplot as plt h = 0.001 x = np.arange(0,2,h) y = x*0 y[0] = 5 for n in range(1,len(x)): y[n]=y[n-1]+h*y[n-1]*(1-y[n-1]) plt.plot(x,y)
import numpy as np import matplotlib.pyplot as plt x = np.arange(2,8,0.001) y = x*(x**2-1)*(np.sin(x)-1/2)*(6*x-2) plt.plot(x,y) x1 = np.arange(7,8,0.001) y1 = x1*(x1**2-1)*(np.sin(x1)-1/2)*(6*x1-2) s = np.sum(y1[1:]+y1[:-1])/2*0.001 print(s)
l=[1,1] for i in range(13): l.append(l[i]+l[i+1]) print(l) print("the answer is =", l[14])
import numpy as np import matplotlib.pyplot as plt x = np.arange(0,2,0.001) y = x*0 y[0]=1 h=0.001 for n in range(1,len(x)): y[n]=y[n-1]+h*(y[n-1]+np.cos(y[n-1])) plt.plot(x,y)
a = np.arange(0,6.29,0.01) plt.plot(np.cos(a)*3,np.sin(a)*3) plt.plot(np.cos(a)*2+5,np.sin(a)*2) plt.plot(np.cos(a)+8,np.sin(a))
x = np.array([-1,-1,1,1,-1]) y = np.array([1,-1,-1,1,1]) for j in range(1,5): plt.plot(j*x,j*y)
import numpy as np import matplotlib.pyplot as plt x = np.arange(1,2,h) h = 0.001 y = x*0 y[1] = 1 for j in range(1,len(x)): y[j] = y[j-1] + h*(y[j-1] + x[j-1]**2) plt.plot(x,y)
import numpy as np import matplotlib.pyplot as plt x = np.array([-1,-1,1,1,-1,0,1]) y = np.array([1,-1,-1,1,1,2,1]) plt.plot(x,y)
import numpy as np import matplotlib.pyplot as plt a = np.arange(0,2*np.pi+1,2*np.pi/9) plt.plot(np.cos(a),np.sin(a))
import numpy as np y = np.array([1,2,3,4,5]) y1 = y[:-1] y2 = y[1:] x = y2*y1 print(x)
import numpy as np x = np.arange(1,1601+1,8) print(sum(x))
import numpy as np x1 = np.arange(1,1601+1,16) x2 = np.arange(-9,-1601+1,-16) b = sum(x1) + sum(x2) print(b)
import numpy as np import matplotlib.pyplot as plt x = np.arange(0.5,2.2,0.001) y = x**3 - 4.5*x**2 + 6.5*x - 3 plt.plot(x,y) y1 = np.argwhere(np.diff(np.heaviside(y,0))) plt.plot(x[y1],y[y1],'ro') y2 = np.diff(y)/np.diff(x) y3 = np.argwhere(np.diff(np.heaviside(y2,0))) plt.plot(x[y3],y[y3],'go')
import numpy as np y = np.array([1,2,3,4,5]) y1 = y[:-1] y2 = y[1:] x = y2*y1 - y1 print(x)
import numpy as np def func(y): y1 = y[:-1] y2 = y[1:] return y2*y1 - y1 print(func(np.array([1,2,3,4,5])))
import numpy as np import matplotlib.pyplot as plt x = np.arange(2,3,0.001) y = (x**3-1)*(np.sin(x)**2-1)*(4*x-4) - np.sin(x) + 1 plt.plot(x,y) x1 = np.arange(2,4,0.001) y1 = (x1**3-1)*(np.sin(x1)**2-1)*(4*x1-4) - np.sin(x1) + 1 s = np.sum(y1[1:]+y1[:-1])/2*0.001 print(s)
l=[1,1] for i in range(250): l.append(l[i]+l[i+1]) for j in l: if j%5==0: print(j)
import numpy as np import matplotlib.pyplot as plt a = np.arange(0,2*np.pi,0.001) plt.plot(np.cos(a),np.sin(a)) x = np.array([-1,-1,1,1,-1]) y = np.array([1,-1,-1,1,1]) plt.plot(x,y)
import numpy as np import matplotlib.pyplot as plt h=0.001 x = np.arange(2,5,h) y = x*0 y[2]=2 for n in range(1,len(x)): y[n] = (2*y[n-1]*h) + y[n-1] plt.plot(x,y) y1 = np.diff(y)/np.diff(x) plt.plot(x[:-1],y1)
import numpy as np import matplotlib.pyplot as plt a = np.arange(0,2*np.pi,0.001) plt.plot(np.cos(a),np.sin(a)) x = np.array([0,2,2,0,0]) y = np.array([2,2,4,4,2]) plt.plot(x,y) x1 = np.array([0,2,0,0]) y1 = np.array([0,0,2,0]) plt.plot(x1,y1)
import numpy as np a = np.diff(np.diff([1,1,1,2,2,2])) print("התשובה בשאלה 1 היא =", a) b = np.heaviside(np.heaviside([-1, 0 ,-1, -1],-1),-1) print("התשובה בשאלה 2 היא =",b) c = 5*sum(np.diff(np.heaviside([1,1,1,2,2,2,1,1,1]))) print("התשובה בשאלה 3 היא =",c) x=[-1,0,-1,-1] for j in range(2000000): x=np.heaviside(np.heaviside(x,-1),-1) print(x)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-132-88d030fc7ef9> in <module>()
6 print("התשובה בשאלה 2 היא =",b)
7
----> 8 c = 5*sum(np.diff(np.heaviside([1,1,1,2,2,2,1,1,1])))
9 print("התשובה בשאלה 3 היא =",c)
10
ValueError: invalid number of arguments
import numpy as np import matplotlib.pyplot as plt x = np.array([-0.2,0.2,0.2,0.5,0,-0.5,-0.2,-0.2]) y = np.array([0,0,4,4,8,4,4,0]) plt.plot (x,y) beta = 180/40*3.28 x1 = y*np.cos(beta)-x*np.sin(beta) plt.plot(x1,y)
import numpy as np import matplotlib.pyplot as plt x = np.arange(-3,3,0.001) y = x*(x+1)*(x+2)*(x-1)*(x-2) plt.plot(x,y) y1 = np.diff(y)/np.diff(x) plt.plot(x[:-1],y1) y2 = np.argwhere(np.diff(np.heaviside(y,0))) plt.plot(x[y2],y[y2],'ro') y3 = np.argwhere(np.diff(np.heaviside(y1,0))) plt.plot(x[y3],y[y3],'go') y4 = np.diff(y1)/np.diff(x[:-1]) y5 = np.argwhere(np.diff(np.heaviside(y4,0))) plt.plot(x[y5],y[y5],'bo') print(x[y2])
import numpy as np import matplotlib.pyplot as plt def mse(x): l = x**2 return sum(l)/len(x) mse(np.array([2,4,6,8]))