I'm working through the bisection method to find the root of a function. I'm asking patience (yet again) because I haven't used this method for a while. I found the formula on wikipedia.
Pseudocode is as follows:
start loop
Do While (xR - xL) > epsilon
'calculate midpoint of domain
xM = (xR + xL) / 2
'Find f(xM)
If ((f(xL) * f(xM)) > 0 Then
'throw away left half
xL = xM
else
'throw away right half
xR = xM
End If
Loop
I'm trying to make my way through this and I have some questions about how Python handles an equation like 5x^8 - 3x^4 + x - 2? If I try it from the shell I get an error message from the x since its with the 5, so I assume it confused about what I'm asking.
A friend told me to use eval(function) but I'm not sure how to use it in my code, or if it is even the best way to go.
Mind you, this is a starting point. There will be MANY more questions before I'm done with this assignment.
The function is to look like this:
def root_find(f, xLo, xHi, eps)
So, if I test the above so that f = 5x**8 - 3x**4 + x - 2. by saying y0 = f(xLo) I will get an error, right? How do I format the input so the function will use it? Am I even asking the right question? (I'm so lost!)
thank you for helping
Pseudocode is as follows:
start loop
Do While (xR - xL) > epsilon
'calculate midpoint of domain
xM = (xR + xL) / 2
'Find f(xM)
If ((f(xL) * f(xM)) > 0 Then
'throw away left half
xL = xM
else
'throw away right half
xR = xM
End If
Loop
I'm trying to make my way through this and I have some questions about how Python handles an equation like 5x^8 - 3x^4 + x - 2? If I try it from the shell I get an error message from the x since its with the 5, so I assume it confused about what I'm asking.
A friend told me to use eval(function) but I'm not sure how to use it in my code, or if it is even the best way to go.
Mind you, this is a starting point. There will be MANY more questions before I'm done with this assignment.
The function is to look like this:
def root_find(f, xLo, xHi, eps)
So, if I test the above so that f = 5x**8 - 3x**4 + x - 2. by saying y0 = f(xLo) I will get an error, right? How do I format the input so the function will use it? Am I even asking the right question? (I'm so lost!)
thank you for helping
Comment