Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 1735
Image: ubuntu1804
Kernel: Python 3 (system-wide)
import numpy as np import matplotlib.pyplot as plt h = 0.01 x = np.arange(2,5,h) y = x*0 y[0] = 2 for j in range(len(x)-1): y[j+1] = 2*h*y[j]+y[j] plt.subplot(1,2,1) plt.plot(x,y,'b') y = np.diff(y)/np.diff(x) plt.subplot(1,2,2) plt.plot(x[1:],y,'r')
[<matplotlib.lines.Line2D at 0x7f26cf1db2e8>]
Image in a Jupyter notebook
counter = 0 num = 0 num1 = 1 num2 = 1 arr = np.zeros(50) while counter != 50: num2 = num1+num num = num1 num1 = num2 if num2%5 == 0: arr[counter] = num2 counter+=1 print(arr)
[5.00000000e+00 5.50000000e+01 6.10000000e+02 6.76500000e+03 7.50250000e+04 8.32040000e+05 9.22746500e+06 1.02334155e+08 1.13490317e+09 1.25862690e+10 1.39583862e+11 1.54800876e+12 1.71676802e+13 1.90392491e+14 2.11148508e+15 2.34167283e+16 2.59695497e+17 2.88006719e+18 3.19404346e+19 3.54224848e+20 3.92841376e+21 4.35667763e+22 4.83162953e+23 5.35835925e+24 5.94251148e+25 6.59034622e+26 7.30880595e+27 8.10559001e+28 8.98923707e+29 9.96921668e+30 1.10560307e+32 1.22613260e+33 1.35980189e+34 1.50804340e+35 1.67244576e+36 1.85477077e+37 2.05697230e+38 2.28121724e+39 2.52990869e+40 2.80571173e+41 3.11158199e+42 3.45079731e+43 3.82699286e+44 4.24420012e+45 4.70689006e+46 5.22002106e+47 5.78909207e+48 6.42020149e+49 7.12011256e+50 7.89632583e+51]
import numpy as np import matplotlib.pyplot as plt x = np.arange(0,6.29,0.01) plt.plot(np.sin(x),np.cos(x)) x = np.array([-1,1,1,-1,-1]) y = np.array([1,1,-1,-1,1]) plt.plot(x,y)
[<matplotlib.lines.Line2D at 0x7f26cefe84a8>]
Image in a Jupyter notebook
import numpy as np import matplotlib.pyplot as plt x = np.array([0,1.25,0.5,0.5,-0.5,-0.5,-1.25,0]) y = np.array([2,0.75,0.75,-0.75,-0.75,0.75,0.75,2]) plt.plot(x,y,'b') a = 90 # in dgrees a = a*3.14 / 180 #to radian x1 = x*np.cos(a)-y*np.sin(a) y1 = x*np.sin(a)+y*np.cos(a) plt.plot(x1,y1,'g')
[<matplotlib.lines.Line2D at 0x7f2529aac7f0>]
Image in a Jupyter notebook
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) z1 = np.heaviside(y,0) z2 = np.diff(z1) vec = np.argwhere(z2!=0) plt.plot(x[vec],y[vec],'go') print(x[vec]) z1 = np.heaviside(y1,0) z2 = np.diff(z1) vec = np.argwhere(z2==-1) plt.plot(x[vec],y[vec],'ro') y2 = np.diff(y1)/np.diff(x[1:]) z1 = np.heaviside(y2,0) z2 = np.diff(z1) vec = np.argwhere(z2!=0) plt.plot(x[vec],y[vec],'ko') plt.grid() ''' [[-2.00000000e+00] [-1.00000000e+00] [-3.30402372e-13] [ 1.00000000e+00] [ 2.00000000e+00]] '''
[[-2.00000000e+00] [-1.00000000e+00] [-3.30402372e-13] [ 1.00000000e+00] [ 2.00000000e+00]] [(array([-2.]), array([-2.64321898e-12])), (array([-1.]), array([1.32160949e-12])), (array([-3.30402372e-13]), array([-1.32160949e-12])), (array([1.]), array([2.64321898e-12])), (array([2.]), array([-1.32160949e-11]))]
Image in a Jupyter notebook
import numpy as np import matplotlib.pyplot as plt x = np.array([0,1,0,0,1,1,0,0]) y = np.array([0,0,1,1.5,1.5,1,1,0]) plt.plot(x,y,'k') x = np.arange(0,6.29,0.01) plt.plot(0.5*np.sin(x),0.5*np.cos(x),'k')
[<matplotlib.lines.Line2D at 0x7f26cca12550>]
Image in a Jupyter notebook
import numpy as np import matplotlib.pyplot as plt y1 = np.array([1,2,3]) y2 = np.array([3,4,5]) def mse(y): return np.sum(y**2)/len(y) print(mse(y1-y2))
4.0
import numpy as np y = np.array([1,2,3,4]) y1 = y[0] yn_1 = y[1:] y = y[:-1] b = y*yn_1 - y1 print(r)
[2 3 4] [1 2 3] [ 1 5 11]
import numpy as np import matplotlib.pyplot as plt x = np.arange(2,3,0.01) y = (x**3-1)*(np.sin(x)**2-1)*(4*x-4)-np.sin(x)+1 plt.plot(x,y) x = np.arange(2,4,0.01) y = (x**3-1)*(np.sin(x)**2-1)*(4*x-4)-np.sin(x)+1 area = np.abs(np.sum(((y[1:]+y[:-1])/2)*np.diff(x))) print(area)
399.69892927735634
Image in a Jupyter notebook
from numpy import diff,heaviside x=[-1,0,-1,-1] heaviside(heaviside([-1,0,-1,-1],-1),-1) print (x)
[-1, 0, -1, -1]