Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. 1
  2.  
  3. import numpy as np
  4. import matplotlib.pylab as plt
  5. b = 4
  6. def f(x):
  7. return x + b
  8. x = 2
  9. a= 3
  10. y = 3
  11.  
  12.  
  13. if f(x+y) == f(x) +f(y) and f(a*x)== a*f(x):
  14.  
  15. print("funkcja jest liniowa")
  16.  
  17. else:
  18.  
  19. print("funkcja nie jest liniowa")
  20.  
  21. 2
  22. import numpy as np
  23. import matplotlib.pylab as plt
  24. def wartosc(f,x=0):
  25. return eval(funkcja,{'x':x})
  26.  
  27. funkcja =input("f(x)=")
  28. xmin=0.0
  29. xmax = 5.0
  30. x=np.arange(xmin,xmax,0.1)
  31. y=1*x
  32.  
  33. for i in range(0,len(x)):
  34. y[i]=wartosc(funkcja,x[i])
  35.  
  36.  
  37.  
  38. def bisection_method(a, b):
  39. if wartosc(funkcja,a)*wartosc(funkcja,b) > 0:
  40. #end function, no root.
  41. print("No root found.")
  42. else:
  43. while (b - a)/2.0 > 1e-6:
  44. midpoint = (a + b)/2.0
  45. if wartosc(funkcja,midpoint) == 0:
  46. return(midpoint) #The midpoint is the x-intercept/root.
  47. elif wartosc(funkcja,a)*wartosc(funkcja,midpoint) < 0: # Increasing but below 0 case
  48. b = midpoint
  49. else:
  50. a = midpoint
  51.  
  52. return(midpoint)
  53.  
  54.  
  55. print(bisection_method(xmin,xmax))
  56.  
  57.  
  58. x0=(bisection_method(xmin,xmax))
  59. y0=wartosc(funkcja,x0)
  60. plt.plot(x,y,lw=2)
  61. plt.plot(x0,y0,"ro",ms=10)
  62. plt.text(x0,y0,"f(x)=0)")
  63. plt.show()
  64.  
  65. 3
  66. import matplotlib.pyplot as plt
  67. import numpy as np
  68. x0=float(input('podaj x srodka okregu;'))
  69. y0=float(input('podaj y srodka okregu;'))
  70. r=float(input('podaj promien okregu;'))
  71. dokladnosc=0.001
  72. x=np.arange(x0-r, x0+r+dokladnosc, dokladnosc)
  73. y=[]
  74.  
  75. #góra
  76. for a in x:
  77. y.append(abs(r**2-(a-x0)**2)**0.5+y0)
  78. #góra
  79. for a in x[::-1]:
  80. y.append(-(abs(r**2-(a-x0)**2)**0.5)+y0)
  81.  
  82. #koordynaty
  83. x=list(x)+list(x[::-1])
  84. plt.plot(x,y, 'm-')
  85. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement