This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's TI-BASIC subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. TI-Basic => TI-BASIC
Author Message
thornahawk
μολών λαβέ


Active Member


Joined: 27 Mar 2005
Posts: 569

Posted: 07 Jun 2010 08:59:09 am    Post subject:

Numerical differentiation is often a risky endeavor. Remembering that approximating a derivative is the same as dividing a near-zero quantity (usually obtained by subtracting near-equal quantities) by another near-zero quantity, this is (partly) the reason why numerical differentiation is never as easy as, say, numerical integration.

Notwithstanding this, here is a TI-BASIC routine to estimate the value of an O-th order derivative of a function at a specified X value.


Code:

PROGRAM:DFN
:Input "F(X)=",Str0
:Str►Equ(Str0,Y₀):FnOff 0
:Input "ORDER: ",O
:If O<0 or fPart(O)
:Stop
:2fPart(O/2)→E
:int((O+E-2)/2)→P
:P≥0→Q
:Prompt X
:abs(X)E-2→H \\ E-2 == 10^(-2
:E-9→T \\ tolerance (increase for greater speed but less accuracy); E-9 == 10^(-9
:DelVar Y:H→U
:If not(E):Then
:Y₀(X)→S:S→Y
:End
:DelVar K
:While K≤9 and Q
:U²→F
:K(K+3)/2→M
:M+1→dim(∟C)
:If E:Then
:nDeriv(Y₀(Z),Z,X,U)→C
:Else
:((Y₀(X+U)-S)-(S-Y₀(X-U)))/(2F)→C \\ yes, the parentheses are crucial
:End
:C→∟C(M+1)
:For(J,1,K)
:F-(H(2K-2J+1))²→Z
:For(I,0,min(J,P))
:M+J→L
:DelVar V
:∟C(L)→W
:If I<J
:W+(∟C(L-K-1)-W)(F/Z)→V
:DelVar W
:If 0<I
:(∟C(L+1)-∟C(L-K))/Z→W
:V+W→∟C(M)
:M-1→M
:End
:If P<J:M-J+P→M
:End
:If K≥P:Then
:Y→R
:(2P-E+2)!∟C(K-P+1)→Y
:abs(Y-R)>Tabs(Y)→Q \\ convergence criterion
:End
:U+2H→U:K+1→K
:End
:DelVar ∟C
:DelVar ∟DF
:Y


The program prompts for the function, derivative order, and the point where the function's derivative is to be estimated. The program tries for maximum possible accuracy in the estimate, but (usually) higher-order derivatives are computed with a larger error than lower order ones, depending on the function and the neighborhood of the X value given. If the function given to it is pathological enough, it can give completely wrong answers, since the algorithm assumes smoothness (i.e. first few derivatives of the function should be continuous) of the function.

The algorithm is adapted from these papers.

thornahawk


Last edited by Guest on 09 Jun 2010 08:11:57 am; edited 1 time in total
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement