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.Wed, 10 Oct 2018 09:22:46 +0200Numerical calculation speed: Sagemath vs. C vs. Matlabhttps://ask.sagemath.org/question/43893/numerical-calculation-speed-sagemath-vs-c-vs-matlab/I mostly use Sagemath for performing symbolic operations on trigonometric polynomials. But I was wondering if it is also a good tool in numerical methods. This includes matrix operations and iterative solution of PDEs with finite difference methods. Usually I take the Sagemath outputs in another program more suited to numerical work. But I was wondering if Sagemath itself is a viable choice in this resepct. Can you tell me about its numerical performance and speed compared to other programs such as C, Matlab, Julia, Mathematica etc.? ThanksDanialBaghWed, 10 Oct 2018 09:22:46 +0200https://ask.sagemath.org/question/43893/How 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?
OrangeMon, 25 Jan 2016 19:09:28 +0100https://ask.sagemath.org/question/32333/Using sage to derive symbolic finite difference approximations to differential equations.https://ask.sagemath.org/question/9967/using-sage-to-derive-symbolic-finite-difference-approximations-to-differential-equations/I am currently working with a finite difference numerical method of advection-diffusion equation. This generated pages of maths, and it is sometime difficult to see where I have made a mistake. As the finite-difference approach is essentially a Taylor expansion with some re-arrangement I was wondering if anybody has used sage to help with writing, re-arrange and factoring finite difference expressions?
I have been using Sage a lot to check my results, but this involves typing long equations, treating subscripts as difference variables, which is error prone. My hope is that by using sage from the first step (i.e. a taylor expansion and so on) not only with the result be less error prone but it will be really quick to experiment with other finite-difference schemes.
So to summarise,
1. Is there a better way to deal with subscripted/superscripted equation other than make a variables which have horrible names e.g. "phi_jm1_np1" = $\phi_{j-1}^{n+1}$
2. Has anybody used sage to derive finite difference equations?
**Example**
For example, let's take the advection term,
$\frac{\partial u}{\partial t} = \boldsymbol{v}\frac{\partial u}{\partial x}$
After apply [Crank-Nicholson](http://en.wikipedia.org/wiki/Crank%E2%80%93Nicolson_method) discretization (which takes the average of the current (n) and future (n+1) time step where the n+1 values are unknowns),
$ \frac{\phi_{j}^{n+1} - \phi_{j}^{n}}{\Delta t} =
\boldsymbol{v} \left[ \frac{1-\beta}{2\Delta x} \left( \phi_{j+1}^{n} - \phi_{j-1}^{n} \right) + \frac{\beta}{2\Delta x} \left( \phi_{j+1}^{n+1} - \phi_{j-1}^{n+1} \right) \right]$
Putting the unknowns on the right-hand side enables this to be written in the linear form,
$\beta r\phi_{j-1}^{n+1} + \phi_{j}^{n+1} -\beta r\phi_{j+1}^{n+1} = -(1-\beta)r\phi_{j-1}^{n} + \phi_{j}^{n} + (1-\beta)r\phi_{j+1}^{n}$
This is now a matrix equation which can be solved in the usual way. The solving step I am happy to do outside of Sage. But I would love to to use Sage to help me derive a finite-difference scheme.boyfarrellSun, 31 Mar 2013 22:59:49 +0200https://ask.sagemath.org/question/9967/