Giter Site home page Giter Site logo

differentiation-using-python's Introduction

파이썬으로 미분하기

미분의 정의는 h가 0으로 갈때 (f(x+h)-f(x))/h 를 구하는 것이나 코드로 미분을 짤 때에는 이와 같은 전방 차분은 오차가 발생할 수 있으므로 중심차분 혹은 중앙 차분으로 미분한다. 그 식은 (f(x+h)-f(x-h))/2*h이다. 이를 파이썬 코드로 나타내면
if __name__ == '__main__':
    
    def f(x):
        return x**2 + 2*x + 4
    
    def numerical_diff(f, x):
        h = 1e-4
        return (f(x+h)-f(x-h))/(2*h)
    
    a = numerical_diff(f, 3)
    print(a)
    
    pass
h를 1e-4(0.0001)로 하는 이유는 h를 너무 작은 수로 했을 경우 컴퓨터가 계산을 잘 하지 못한다. 10^-4 정도 되면 좋은 결과를 얻는다고 알려져 있다.

differentiation-using-python's People

Contributors

jis1218 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.