Bisection Method In Python | Numerical Methods

preview_player
Показать описание
In this video, let’s implement the bisection method in Python. The bisection method is a non-linear numerical root solver that is commonly taught in numerical methods courses. Through this code we can solve for the roots of any function through the bisection method being defined as a function in Python.

Follow & Support StudySession:

What is Python and why you should learn Python? Python programming, in particular Python 3, is a growing programming language that is loved by many programmers due to its simple syntax and ease of use. Python allows for relatively easy debugging of your codes and there are many beautiful Python IDE’s available for free to make coding more enjoyable. Python is also very popular among Data Scientists and many machine learning applications.
Рекомендации по теме
Комментарии
Автор

You Sir just explained in 3 minutes stuff that my professor tried to explain for 30 minutes and nobody understood. Thank you!

antekkalafior
Автор

It is insane how well this video is made

wshcc
Автор

def bisection_method(func, a, b, error_accept):
"""
This function solves for an unknown root of non-linear funktion given the function, the initial root boundaries,
and an acceptable level of error.

Parameters

func : The user defined function, witch needs to be entered as a string.
a : The inital lower root boundray.
b : The inital upper root boundray.
error_accept : The user's acceptable level of error

Returns

f : The root boundraies and the error at the final iteration.

"""


def f(x):
f=eval(func)
return f

error=abs(b-a)

while error > error_accept:
c=(b+a)/2

if f(a)*f(b)>=0:
print("No root multiple roots present, therefore, the bisection method will not work!")
quit()

elif f(c)*f(a)<0:
b=c
error=abs(b-a)

elif f(c)*f(b)<0:
a=c
error=abs(b-a)

else:
print("something went wrong")
quit()

print(f"the error is {error}")
print(f"the lower boundary, a, is {a} and the upper boundray, b, is {b}")



bisection_method("(4*x**3)+3*x-3", 0, 1, 0.05)

bisection_method("(3*x**2)-4", -2, 0, 0.05)

samramzi
Автор

I will use this video as a reference to my project

cristianortiz
Автор

Sir is it possible to create a user input for the equation that users want to give?

nathanaeltomaterado
Автор

Nice video. I feel it would have been nice if it just printed the final root out
And also please can you provide the code

BankoleAyodeleMEG
Автор

💙Thank alot that is amazing, thank you for your time 💙

developerx
Автор

what if I need to use cos(x) and sin(x) in my function? does the eval work? Thanks for the video.

pedrobrant
Автор

how to determine a and b programmaticaly

richardpatove
visit shbcf.ru