ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 28 Jan 2016 13:14:29 +0100How to define finite difference approximation for first order derivativehttps://ask.sagemath.org/question/32333/how-to-define-finite-difference-approximation-for-first-order-derivative/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?
Mon, 25 Jan 2016 19:09:28 +0100https://ask.sagemath.org/question/32333/how-to-define-finite-difference-approximation-for-first-order-derivative/Answer by tmonteil for <p>I need to define $$y1(k)=\frac{y_{k+1}-y_{k-1}}{2*h}$$</p>
<p>in sage so that sage can differ between symbolic $$y_{k+1}$$ and $$y_{k}$$.</p>
<p>Would somebody please help?</p>
https://ask.sagemath.org/question/32333/how-to-define-finite-difference-approximation-for-first-order-derivative/?answer=32335#post-id-32335The 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]
Tue, 26 Jan 2016 09:22:44 +0100https://ask.sagemath.org/question/32333/how-to-define-finite-difference-approximation-for-first-order-derivative/?answer=32335#post-id-32335Comment by Orange for <p>The question is not clear to me, why not simply do:</p>
<pre><code>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]
</code></pre>
https://ask.sagemath.org/question/32333/how-to-define-finite-difference-approximation-for-first-order-derivative/?comment=32350#post-id-32350$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!!!Thu, 28 Jan 2016 13:14:29 +0100https://ask.sagemath.org/question/32333/how-to-define-finite-difference-approximation-for-first-order-derivative/?comment=32350#post-id-32350