Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1
- import numpy as np
- import matplotlib.pylab as plt
- b = 4
- def f(x):
- return x + b
- x = 2
- a= 3
- y = 3
- if f(x+y) == f(x) +f(y) and f(a*x)== a*f(x):
- print("funkcja jest liniowa")
- else:
- print("funkcja nie jest liniowa")
- 2
- import numpy as np
- import matplotlib.pylab as plt
- def wartosc(f,x=0):
- return eval(funkcja,{'x':x})
- funkcja =input("f(x)=")
- xmin=0.0
- xmax = 5.0
- x=np.arange(xmin,xmax,0.1)
- y=1*x
- for i in range(0,len(x)):
- y[i]=wartosc(funkcja,x[i])
- def bisection_method(a, b):
- if wartosc(funkcja,a)*wartosc(funkcja,b) > 0:
- #end function, no root.
- print("No root found.")
- else:
- while (b - a)/2.0 > 1e-6:
- midpoint = (a + b)/2.0
- if wartosc(funkcja,midpoint) == 0:
- return(midpoint) #The midpoint is the x-intercept/root.
- elif wartosc(funkcja,a)*wartosc(funkcja,midpoint) < 0: # Increasing but below 0 case
- b = midpoint
- else:
- a = midpoint
- return(midpoint)
- print(bisection_method(xmin,xmax))
- x0=(bisection_method(xmin,xmax))
- y0=wartosc(funkcja,x0)
- plt.plot(x,y,lw=2)
- plt.plot(x0,y0,"ro",ms=10)
- plt.text(x0,y0,"f(x)=0)")
- plt.show()
- 3
- import matplotlib.pyplot as plt
- import numpy as np
- x0=float(input('podaj x srodka okregu;'))
- y0=float(input('podaj y srodka okregu;'))
- r=float(input('podaj promien okregu;'))
- dokladnosc=0.001
- x=np.arange(x0-r, x0+r+dokladnosc, dokladnosc)
- y=[]
- #góra
- for a in x:
- y.append(abs(r**2-(a-x0)**2)**0.5+y0)
- #góra
- for a in x[::-1]:
- y.append(-(abs(r**2-(a-x0)**2)**0.5)+y0)
- #koordynaty
- x=list(x)+list(x[::-1])
- plt.plot(x,y, 'm-')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement