Ask Your Question
1

How to define finite difference approximation for first order derivative

asked 2016-01-25 12:09:28 -0500

Orange gravatar image

updated 2016-01-26 02:00:49 -0500

tmonteil gravatar image

I need to define $$y1(k)=\frac{y_{k+1}-y_{k-1}}{2*h}$$

in sage so that sage can differ between symbolic $$y_{k+1}$$ and $$y_{k}$$.

Would somebody please help?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-01-26 02:22:44 -0500

tmonteil gravatar image

The question is not clear to me, why not simply do:

sage: Y = [1,2,4,3,7,2,1]
sage: h = 0.1
sage: [(Y[k+1]-Y[k-1])/h for k in  range(1,len(Y)-1)]
[30.0000000000000,
 10.0000000000000,
 30.0000000000000,
 -10.0000000000000,
 -60.0000000000000]
edit flag offensive delete link more

Comments

$y_{k+1} $ and $y_k$ needs to remain unknown till the formation of equation, so that they can act as variables in the linear system. My interest is to automate the finite difference method in sage. Should I need to define some new data structure. Thanks for responding though!!!

Orange gravatar imageOrange ( 2016-01-28 06:14:29 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2016-01-25 12:09:28 -0500

Seen: 103 times

Last updated: Jan 26 '16