Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 16 Online
OpenStudy (harsimran_hs4):

this is the code i have written for ps2 http://pastebin.com/GawtDFrL there is a error in the last part i.e to calculate the root of the polynomial.please could you let me know my mistake. (about newton's method)

OpenStudy (anonymous):

I found a few bugs. http://pastebin.com/U8KcLmuQ has the corrections Line 4 should be valpoly = valpoly + (poly[i]*x**i) instead of valpoly = sumpoly + (poly[i]*x**i) also, you need to have your functions return values so add return valpoly as line 5 of your evaluate_poly function and return deriv should be added at the end of compute_deriv lastly, you need to add some harness code to run the functions. polyMy = (-13.39, 0.0, 17.5, 3.0, 1.0) print compute_root(polyMy, .01, .0001)

OpenStudy (harsimran_hs4):

thanks a lot...was the main mistake that i didn`t return the value in the function?

OpenStudy (anonymous):

yes, both evaluate_poly and compute_deriv needed to return a value

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!