Python Forum
[split] f1(), f2() lambda functions addition
Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] f1(), f2() lambda functions addition
#9
Hi

Now when I am running the code I am getting the output correctly. Here is the code for future references:

def newton_raphson(f,guess,tolerance,max_iter,increment,epsilon):
    for iter in range(max_iter):
        func_value=f(guess)
        fprime=(f(guess+increment)-f(guess-increment))/(2.0*increment) 
        if (abs(fprime)>epsilon):
            next_guess=guess-(float(func_value)/float(fprime))
            if(abs(next_guess-guess)<=tolerance*abs(next_guess)) or fprime==0:
                break
            else:
                    guess=next_guess                      
        else: break
    print("Root of the function %s is: %f" %(f,next_guess) )
    
if __name__=="__main__":
    newton_raphson(lambda x:x**2-x*4,5,.000001,100,.001,.001)
Thanks for your help !
Reply


Messages In This Thread
RE: [split] f1(), f2() lambda functions addition - by baby_quant - Sep-14-2018, 04:14 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Homework on addition with working paperplanexx 1 2,490 Aug-19-2018, 12:40 PM
Last Post: j.crater
  f1(), f2() lambda functions addition Danielk121 5 5,745 Dec-02-2017, 09:27 AM
Last Post: Danielk121

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020