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

Hi, I'm working on Problem Set 2, and I'm having some trouble with the second problem. Can anyone post a sample solution? Thanks.

OpenStudy (anonymous):

If you describe the trouble you're having, I can try to walk you through the concepts. It seems pointless to solve the problem for you, since solving it yourself is actually the point of the exercise.

OpenStudy (anonymous):

solution to psets are also given there

OpenStudy (anonymous):

Thank you for your reply. Problem #2 on Problem Set 2 asks for a program that can find the derivative of a polynomial function. It hints that we should tackle each individual term, stringing each term's derivative together to find the derivative of the whole function. I'm using two functions to try and solve this: one finds the derivative of a given term (deriv_one_term), and the other performs the action on all the terms in the polynomial (compute_deriv). I've copied what I have so far below: def deriv_one_term(term, power): if power <= 0: return 0 else: derivative = term * (power ** (power - 1)) return(derivative) def compute_deriv(poly): result = (0, ) """ Computes and returns the derivative of a polynomial function. If the derivative is 0, returns (0.0, ). Example: >>> poly = (-13.39, 0.0, 17.5, 3.0, 1.0) # x4 + 3.0x3 + 17.5x2 - 13.39 >>> print compute_deriv(poly) # 4.0x3 + 9.0x2 + 35.0x (0.0, 35.0, 9.0, 4.0) poly: tuple of numbers, length > 0 returns: tuple of numbers """ for i in range(len(poly)): result += (deriv_one_term(poly[i], i), ) return result Giving the second program the input (-13.39, 0.0, 17.5, 3.0, 1.0) should return (0.0, 35.0, 9.0, 4.0), but instead it returns (0, 0, 0.0, 35.0, 27.0, 64.0). Any help is appreciated.

OpenStudy (anonymous):

pls use a code pasting site: http://dpaste.com http://pastebin.comhttp:// http://codepad.org the derivative of the function with coefficients of (-13.39, 0.0, 17.5, 3.0, 1.0) should be: (0.0, 35, 9.0, 4.0) http://dpaste.com/766647/

OpenStudy (anonymous):

Thanks.

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!