CoCalc Public Fileswork.ipynbOpen with one click!
Author: ori cohen
Views : 12
Compute Environment: Ubuntu 18.04 (Stable)
In [2]:
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)
[<matplotlib.lines.Line2D at 0x7fcb7bf6a290>]
In [8]:
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')
[<matplotlib.lines.Line2D at 0x7fcb7baf4350>]
In [2]:
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])
[[-5.01] [-4. ] [-3. ] [-2. ] [-1. ]]
In [4]:
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])
[[-4.65] [-3.55] [-2.47] [-1.37]]
In [1]:
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')
In [5]:
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();
In [3]:
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')
[<matplotlib.lines.Line2D at 0x7f5c82c5ee50>]
In [22]:
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)
[<matplotlib.lines.Line2D at 0x7fa2a3fbc950>]
In [4]:
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)
7439.919927737857
In [6]:
l=[1,1] for i in range(13): l.append(l[i]+l[i+1]) print(l) print("the answer is =", l[14])
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610] the answer is = 610
In [2]:
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)
[<matplotlib.lines.Line2D at 0x7f49046f7a10>]
In [22]:
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))
[<matplotlib.lines.Line2D at 0x7f214d9e1e50>]
In [31]:
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)
In [11]:
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)
[<matplotlib.lines.Line2D at 0x7f49045ab990>]
In [1]:
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)
[<matplotlib.lines.Line2D at 0x7f5b23daa910>]
In [4]:
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))
[<matplotlib.lines.Line2D at 0x7f5b23bab050>]
In [11]:
import numpy as np y = np.array([1,2,3,4,5]) y1 = y[:-1] y2 = y[1:] x = y2*y1 print(x)
[ 2 6 12 20]
In [15]:
import numpy as np x = np.arange(1,1601+1,8) print(sum(x))
161001
In [18]:
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)
801
In [2]:
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')
[<matplotlib.lines.Line2D at 0x7f0eba7d0e50>]
In [1]:
import numpy as np y = np.array([1,2,3,4,5]) y1 = y[:-1] y2 = y[1:] x = y2*y1 - y1 print(x)
[ 1 4 9 16]
In [2]:
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])))
[ 1 4 9 16]
In [4]:
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)
-402.6129253735654
In [34]:
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)
5 55 610 6765 75025 832040 9227465 102334155 1134903170 12586269025 139583862445 1548008755920 17167680177565 190392490709135 2111485077978050 23416728348467685 259695496911122585 2880067194370816120 31940434634990099905 354224848179261915075 3928413764606871165730 43566776258854844738105 483162952612010163284885 5358359254990966640871840 59425114757512643212875125 659034621587630041982498215 7308805952221443105020355490 81055900096023504197206408605 898923707008479989274290850145 9969216677189303386214405760200 110560307156090817237632754212345 1226132595394188293000174702095995 13598018856492162040239554477268290 150804340016807970735635273952047185 1672445759041379840132227567949787325 18547707689471986212190138521399707760 205697230343233228174223751303346572685 2281217241465037496128651402858212007295 25299086886458645685589389182743678652930 280571172992510140037611932413038677189525 3111581989804070186099320645726169127737705 34507973060837282187130139035400899082304280 382699285659014174244530850035136059033084785 4244200115309993198876969489421897548446236915 47068900554068939361891195233676009091941690850 522002106210068326179680117059857997559804836265 5789092068864820527338372482892113982249794889765 64202014863723094126901777428873111802307548623680 712011255569818855923257924200496343807632829750245 7896325826131730509282738943634332893686268675876375
In [41]:
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)
[<matplotlib.lines.Line2D at 0x7f4eb059d490>]
In [100]:
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)
[<matplotlib.lines.Line2D at 0x7f4ea2c823d0>]
In [51]:
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)
[<matplotlib.lines.Line2D at 0x7f4eb00e4e50>]
In [132]:
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)
התשובה בשאלה 1 היא = [ 0 1 -1 0] התשובה בשאלה 2 היא = [-1. 0. -1. -1.]
--------------------------------------------------------------------------- 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
In [134]:
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)
[<matplotlib.lines.Line2D at 0x7f4ea2868250>]
In [108]:
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])
[[-2.00000000e+00] [-1.00000000e+00] [-3.30402372e-13] [ 1.00000000e+00] [ 2.00000000e+00]]
In [117]:
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]))
30.0
In [ ]:
In [ ]: