Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Tham khảo tài liệu 'lập trình c# all chap "numerical recipes in c" part 40', công nghệ thông tin phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 186 Chapter5. Evaluation ofFunctions 5.7 Numerical Derivatives Imagine that you have a procedure which computes a function f x and now you want to compute its derivative f 0 x . Easy right The definition of the derivative the limit as h 0 of s o S ffx a f x h - f x 5.7.1 h 0 0 0 71 71 practically suggests the program Pick a small value h evaluate f x h you f j j probably have f x already evaluated but if not do it too finally apply equation i E 5.7.1 . What more needs to be said o S Quite a lot actually. Applied uncritically the above procedure is almost guaranteed to produce inaccurate results. Applied properly it can be the right way to compute a derivative only when the function f is fiercely expensive to compute 5 when you already have invested in computing f x and when therefore you want to get the derivative in no more than a single additional function evaluation. In such a situation the remaining issue is to choose h properly an issue we now discuss I I. There are two sources of error in equation 5.7.1 truncation error and roundoff 2 a error. The truncation error comes from higher terms in the Taylor series expansion O C. Eg f x h f x hf x 1 h2f x 1 tif x 5.7.2 I Hi 2 6 o whence 1 x I - 1 x f 2 hf 5.7.3 fill o O - M W The roundoff error has various contributions. First there is roundoff error in h . . . . . Suppose by way of an example that you are at a point x 10.3 and you blindly e 3 g choose h 0.0001. Neither x 10.3 nor x h 10.30001 is a number with s g- a.- Q. 0 3 an exact representation in binary each is therefore represented with some fractional error characteristic of the machine s floating-point format em whose value in single precision may be 10-7. The error in the effective value of h namely the difference 8 - between x h and x as represented in the machine is therefore on the order of em x g which implies a fractional error in h of order emx h 10-2 By equation 5.7.1 S-a g SS this immediately implies at least the same large fractional error in the