Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

ParthKohli

How to make a function that finds the derivative using python? Is there a built-in one?

  • one year ago
  • one year ago

  • This Question is Open
  1. Chris2332
    Best Response
    You've already chosen the best response.
    Medals 0

    Just create a recursive function that multiplies the factor by the exponential and then decrements the exponent with each call.

    • one year ago
  2. Rohangrr
    Best Response
    You've already chosen the best response.
    Medals 1

    Binding variables as if you want to find the area of a circle use this >>>> pi = 3.14159 >>>> radius = 11.2 >>>> area = pi( radius ** 2) >>>> area = 394.081

    • one year ago
  3. Chris2332
    Best Response
    You've already chosen the best response.
    Medals 0

    Huh? Did I miss something?

    • one year ago
  4. ParthKohli
    Best Response
    You've already chosen the best response.
    Medals 0

    @chris2332: That doesn't work for other functions... only polynomials.

    • one year ago
  5. Rohangrr
    Best Response
    You've already chosen the best response.
    Medals 1

    maybe!!

    • one year ago
  6. Chris2332
    Best Response
    You've already chosen the best response.
    Medals 0

    Something like that? def derivative(f): ....""" ....Computes the numerical derivative of a function. ....""" ....def df(x, h=0.1e-5): ........return ( f(x+h/2) - f(x-h/2) )/h ....return df

    • one year ago
  7. ParthKohli
    Best Response
    You've already chosen the best response.
    Medals 0

    Uh... no

    • one year ago
  8. Chris2332
    Best Response
    You've already chosen the best response.
    Medals 0

    Then what derivative do you want?

    • one year ago
  9. Rohangrr
    Best Response
    You've already chosen the best response.
    Medals 1

    The mathematical definition of the derivative of a function f(x) at point x is to take a limit as "h" goes to zero of the following expression: ( f(x+h) - f(x) ) / h An example is given below: the red curve is the function f(x) and the green curve is the tangent line at x (with same slope as the derivative). The blue curve is a line going through x whose slope equals that of the above formula with a non-zero value of h. A better way of numerically computing the derivative for the same value of "h" is by taking a symmetrical interval around x as follows: ( f(x + h/2) - f(x - h/2) ) / h This is illustrated in the next picture. As you can see, the two straight lines have much more similar slopes - hence, the value computed for the derivative is going to be more accurate. The corresponding python code is as follows: def derivative(f): ....""" ....Computes the numerical derivative of a function. ....""" ....def df(x, h=0.1e-5): ........return ( f(x+h/2) - f(x-h/2) )/h ....return df And we use it as follows: # sample function def g(x): return x*x*x # first derivative dg = derivative(g) # second derivative d2g = derivative(dg) # == derivative(derivative(g)) # printing the value computed at a given point: print dg(3) print dg(3, 0.001) print dg(3, 1e-10) # smaller h is not always more precise source : http://aroberge.blogspot.in/2005/04/computing-derivatives-using-python.html

    • one year ago
  10. Chris2332
    Best Response
    You've already chosen the best response.
    Medals 0

    Exactly... that's where I got the snippet from!

    • one year ago
  11. Rohangrr
    Best Response
    You've already chosen the best response.
    Medals 1

    @ParthKohli where u r??

    • one year ago
  12. estudier
    Best Response
    You've already chosen the best response.
    Medals 1

    from sympy import init_printing, symbols, ln, diff init_printing() x,y = symbols('x y') f = x**2 / y + 2 * x - ln(y) diff(f,x) -> 2*x/y +2

    • one year ago
  13. estudier
    Best Response
    You've already chosen the best response.
    Medals 1

    I am assuming u do not want to reinvent the wheel, so just use sympy....

    • one year ago
  14. TuringTest
    Best Response
    You've already chosen the best response.
    Medals 0

    The next Pset in 6.00x has one problem in which to find the derivative of polynomials written as lists. I would show you the program I wrote but I don't want to give out the answer before the due date.

    • one year ago
  15. ParthKohli
    Best Response
    You've already chosen the best response.
    Medals 0

    Heh, I'm not following that course.

    • one year ago
  16. TuringTest
    Best Response
    You've already chosen the best response.
    Medals 0

    then I will pm my code to you, but don't give it to anyone taking the course

    • one year ago
  17. ParthKohli
    Best Response
    You've already chosen the best response.
    Medals 0

    Yup! I discovered this Python group so thought I'd ask...

    • one year ago
  18. estudier
    Best Response
    You've already chosen the best response.
    Medals 1

    numPy/sciPy are good too....

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.