import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0,11)
y = x+2
plt.figure(figsize=(8,5))
plt.plot(x,y,linestyle=(12, (10, 10)),alpha=0.4,c='green')
plt.scatter(x=2,y=4,s=80,facecolors='none', edgecolors='black')
plt.show()
pip install numpy matplotlib
import numpy as np
import matplotlib.pyplot as plt
def f(x):
return x**2
x = np.linspace(-10,10,100)
y = f(x)
plt.plot(x,y, 'b')
plt.grid()
def df(f):
h= 0.0000001
return (f(x+h) - f(x))/h
plt.plot(x,y,'b')
plt.plot(x,df(f),'r')
plt.grid()
def f(x):
return np.sin(x)
x = np.linspace(-10,10,100)
y = f(x)
def df(f):
h= 0.0000001
return (f(x+h) - f(x))/h
plt.plot(x,y,'b')
plt.plot(x,df(f),'r')
plt.grid()
def df(f):
h=0.000001
return (f(x+h)-f(x))/h
"""Sea
f(x) = mx+b
f'(x) = m
"""
def f(x):
return x
plt.plot(x, f(x), 'b')
plt.plot(x,df(f), 'r')
plt.grid()
def H(x):
Y = np.zeros(len(x))
for idx,x in enumerate(x):
if x>=0:
Y[idx]=1
return Y
N=1000
y = H(x)
plt.plot(x, H(x), 'b')
plt.plot(x,df(H), 'r')
plt.grid()
def f(x):
return 1/(1 + np.exp(-x))
plt.plot(x, f(x), 'b')
plt.plot(x,df(f), 'r')
plt.grid()
def f(x):
return np.tanh(x)
N=1000
y = f(x)
plt.plot(x, f(x), 'b')
plt.plot(x,df(f), 'r')
plt.grid()
def f(x):
return np.maximum(x,0)
N=1000
y = f(x)
plt.plot(x, f(x), 'b')
plt.plot(x,df(f), 'r')
plt.grid()