0

I am asked to write a program to solve this equation ( x^3 + x -1 = 0 ) using fixed point iteration.

What is the algorithm for fixed point iteration? Is there any fixed point iteration code sample in Python? (not a function from any modules, but the code with algorithms)

Thank You

2

2 Answers 2

1

First, read this: Fixed point iteration:Applications

I chose Newton's Method.

Now if you'd like to learn about generator functions, you could define a generator function, and instance a generator object as follows

def newtons_method(n):
    n = float(n)  #Force float arithmetic
    nPlusOne = n - (pow(n,3) + n - 1)/(3*pow(n,2) +1)
    while 1:
        yield nPlusOne
        n = nPlusOne
        nPlusOne = n - (pow(n,3) + n - 1)/(3*pow(n,2) +1)

approxAnswer = newtons_method(1.0)   #1.0 can be any initial guess...

Then you can gain successively better approximations by calling:

approxAnswer.next()

see: PEP 255 or Classes (Generators) - Python v2.7 for more info on Generators

For example

approx1 = approxAnswer.next()
approx2 = approxAnswer.next()

Or better yet use a loop!

As for deciding when your approximation is good enough... ;)

Sign up to request clarification or add additional context in comments.

Comments

0

Pseudocode is here, you should be able to figure it out from there.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.