Finding Zeros of Functions In Python (Bisection Method and Scipy)
Вставка
- Опубліковано 11 лип 2018
- In this video I go over two root finding methods in python. I motivate the Bisection Method on paper before getting into how to write a program to implement it. At the end of the video, I show a quick way to find zeros using the fsolve function from the scipy library.
- Розваги
If you replace tol with 0 in the if else statement you get a much better accuracy
Good catch! Thanks!
@@AndrewDotsonvideos Where exactly? In 6:47?
@@AndrewDotsonvideos lol, i was wondering that
@@AndrewDotsonvideos You are near-criminally underfollowed. Always interesting content.
You're doing gods work. Please more python videos.
You really got to the root of my issue Andrew, thank you!
Here i am discovering your channel again after so many years hahhas. Awesome!
This really helped me finish my python hw I put off to the last minute, so thank you!
Great job! You dissected it very well.
Thank you so much!! You made this so easy to understand
I love this kind of videos!
Love the python videos mate
I am watching your tutorial in Taiwan. Thank you.
Thank you very much, excellent explanation of the procedure
Useful video! Thank you!
Yuu're doing gods work, thanks
Thank u! U saved my life
Can you use this method to find a complex root of a complex function?
I like your binary search xD good video
You can use "elif" instead of nesting "if" inside "else".
Described very well
what's the use of the tolerance ??? we did the same code in fortran for computational physics but didn't understand that tolerance
hi, may i ask if there is another possible way to get two roots without using fsolve?
you call me smart... it goes straight to my head
Which is the best book to learn numerical analysis ?????
Did you learn how to use python for physics mainly on your own or did your courses help you develop those skills? I'm going into my Junior year of physics (Quantum and Thermo this year!) and also starting my minor in comp sci, and I have very little knowledge of coding. Been trying to find resources online for learning to code for math and physics and what not, but i've been unsuccessful lol. We do have a course that works with coding for physics at my uni which I'll probably take next semester or next year. Just want to get ahead of the game though to be valuable during research.
Computational Physics by Nicholas J. Giordano is a great textbook that may help you "learn to code for math and physics." I suspect that you already know, more or less, how to code a simple program (there's a shitload of resources for that), but you don't have experience in solving physics/math problems numerically. If that's the case, then that textbook might come in handy. (There's many ways to get that book online without paying a dime >_>)
Thank you! Yeah, I understand the basics of coding, just don't know how to use the tools of it to solve problems. Alot of the libraries he imported in this video like matplotlib i didn't have so I guess I gotta figure out how to obtain that lol. I'll go check out that book *cough cough* by "purchasing it" *cough cough.
In the bissection method, if values "a" and "b" are root, or any "c" value makes f() function returns zero, the routine enter in an infinite loop
thank you!!
Nice!
how do you get 2 answers for x with the bisection method?
What if you have two roots?
Please do more python videos, you make it so much easier to understand
do u guys have any idea why my code isn't working? after running the code a star will appear in left side and then nothing, i need to re-run the jupyter.
8:00 How on Earth the first function and the second are connected? How does the bisection function understands that it needs to find a different root when the f(x) is changed to the quadratic????!!!
If the interpreter can't find an object inside the function it starts to look for it in the main code. It would be much safer to give f as an argument of the bisection function.
more python videos pls!!
If I put "c = (xl + xr) / 2" line outside the while loop (just after xr = b), it takes forever to run. Can you tell me why is that?
if you define c before the loop starts it will never get updated and therefore the greater than/less than conditions don't effect c.
Could you do Newtons method in Python?
Yes actually!
Hello! Is there any book or free course that explain numerical methods in a simple way? What do you recommend?
I'm using Computational Physics by Mark Newman right now and I find it's my most useful textbook. There are some accompanying materials posted by the author for free online.
How can I get a pdf version please?
I was searching how to do the bisection search.
how did I ended up here.
I had tried so much to find roots of Bessel functions of 1st,2nd or 3rd order, everytime the code screwed up things
If there are multiple roots, the algorithm works regardless, you'll just find one of the roots instead of multiple. You could then search the other intervals by a bisection method to make sure you haven't missed any? (This doesn't work for arbitrary functions since you don't know when to stop, but polynomials, which have at most n roots for degree n, this would work pretty fast I think).
hey at 2:18 shouldn't it be () ? or may be i need to re-understand this, thanks
never mind i got it :) -*- >0
how can i proceed to find all roots of a function in some range (or interval)?
fsolve can give us roots just in specified point (guesses).
Hey, Andrew I had an idea and I would like your input on it. I could be completely and utterly wrong, but I can't shake the idea so I want someone who knows some QM and SR to give me some feedback. Quantum field theory describes antimatter as matter moving backwards through time. If you look at a Feynman diagram of a matter-antimatter annihilation event the antimatter is described as moving in the negative time direction well matter goes in the positive time direction while being mediated by force carrying bosons. This is considered a mathematical trick that has no physical significance and leads to wacky joke theories like the one electron universe theory. Well what if antimatter is just regular matter that is tachyonic. Tachyons are a mathematical trick with lorentz transformations. You can't approach the speed of light because it requires infinite energy to get to because when v = c the entire equation is dividing by 0. Well if you approach it from the opposite direction so you start off being faster than the speed of light then it requires infinite energy to slow down for the exact same reason you can't speed up to being faster than light. When you do this you end up dealing with the square root of a negative number so an imaginary number. Well, we all know that travelling faster than the speed of light is equivalent to travelling backwards in time then is it possible that antimatter is simply the tachyonic equivalent of matter. If you trace a tachyonic worldline it reverses the direction of time. In QFT a little mathematical quirk is just considering antimatter to be time reversed matter so it is just regular matter travelling backwards through time just like a tachyon would. Thanks for any input.
Please it does not work for the function 2*x**2 - 5*x + 3 with xl=0 and xr=1.3. In this case, our solution must be x=1
but using this code, we have the answer
# Let assume that the root is found between x1=0 and x2=1.3
x1=0
x2=1.3
y1=2*x1**2 - 5*x1+3
y2=2*x2**2 - 5*x2+3
if y1*y2>0:
print("the root is not found in the interval")
exit
for bisection in range(1,101):
xh=(x1 + x2)/2
yh=2*xh**2 - 5*xh+3
y1=2*x1**2 - 5*x1+3
if abs(y1)
Thanks Ryan Reynolds
first
Ben Affleck doing python tutorials?
there is always one typo hhhhhhhhhhhhhhh at least :)
this code is so bad...