Ask Your Question
1

How to define finite difference approximation for first order derivative

asked 2016-01-25 19:09:28 +0200

Orange gravatar image

updated 2022-10-15 13:30:18 +0200

FrédéricC 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 09:22:44 +0200

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 13:14:29 +0200 )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 19:09:28 +0200

Seen: 366 times

Last updated: Jan 26 '16