Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- Created on Tue Oct 22 08:18:14 2019
- @author: student
- """
- import numpy as np
- import matplotlib.pyplot as plt
- #def f(x):
- # return 2*x**2 - 4
- #
- #xl = float(input("Unesi lijevu granicu: "))
- #xd = float(input("Unesi desnu granicu: "))
- #epsilon = float(input("Unesi dopustenu gresku: "))
- #
- #x = np.linspace(xl, xd, 100)
- #
- #plt.plot(x, f(x),'r-')
- #plt.axhline(color='black')
- #
- #maxiter = 100
- #it = 0
- #
- #while it < maxiter:
- # xs = (xd+xl) * 0.5
- #
- # error = np.abs(f(xs))
- #
- # if error < epsilon:
- # print("Dopustena greska zadovoljena")
- # break
- # elif f(xs) * f(xd) < 0:
- # xl = xs
- # else:
- # xd = xs
- # it = it + 1
- # print (it, xs)
- #
- #print("Bisekcija x: ", xs)
- #plt.plot(xs, 0, 'bo')
- #def f(x):
- # return 2*x**2 - 4
- #
- #def f_der(x):
- # return 4*x
- #x1 = float(input("Unesi pocetnu tocku: "))
- #epsilon = float(input("Unesi dopustenu gresku: "))
- #
- #X = np.array([x1])
- #maxit = 100
- #it = 1
- #
- #while it < maxit:
- # Xi = X[-1] - f(X[-1]) / f_der(X[-1])
- # X = np.append(X, Xi)
- #
- # error = np.abs(X[-1] - X[-2])
- # if error < epsilon:
- # break
- #
- # it += 1
- #
- #print(it, X[-1])
- import scipy.optimize as opt
- #x0 = opt.fsolve(f, 2)
- #print ("nultocka scipy: ", x0[0])
- #def f(x):
- # return np.cos((x/2.2) -5.5) *5
- #
- #x = np.linspace(0, 24, 100)
- #plt.plot(x, f(x), 'b-')
- #plt.axhline(color = 'black')
- #
- #x0 = opt.fsolve(f, [1,8,14,20])
- #print("nultocka: ", x0)
- #plt.plot(x0, [0, 0, 0, 0], 'k*', label ='0*C')
- #plt.legend()
- def f(x):
- return 1250 * np.sin(x - 2) + 250 * x + 1100 - 1250
- x = np.linspace(0,30,100)
- plt.plot(x, f(x), 'r--')
- plt.axhline(color='black')
- vrijeme = opt.fsolve(f, 2)
- print (vrijeme[0])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement