Ask Your Question

boyfarrell's profile - activity

2019-02-05 03:47:07 -0500 received badge  Notable Question (source)
2019-02-05 03:47:07 -0500 received badge  Popular Question (source)
2016-10-12 04:09:39 -0500 received badge  Nice Question (source)
2015-11-27 03:29:04 -0500 received badge  Famous Question (source)
2014-06-29 14:31:49 -0500 received badge  Popular Question (source)
2014-06-29 14:31:49 -0500 received badge  Notable Question (source)
2014-06-29 14:31:49 -0500 received badge  Famous Question (source)
2014-06-06 22:56:11 -0500 received badge  Notable Question (source)
2013-10-03 17:51:32 -0500 received badge  Popular Question (source)
2013-05-26 17:22:21 -0500 asked a question Can I make plot(f(x)) figures smaller?

The plot command is very useful, but the default size of plots is quite large. Is it possible to reduce the size?

2013-05-26 17:20:32 -0500 marked best answer Using solve() to find an unknown which is a limit of integration?

For such an easy example, Sage is able to do it in the following way:

sage: var('x,c,m,t')
(x, c, m, t)
sage: f(x) = m*x + c

sage: solve([f.integral(x,0,t) == 0], t)
[t == -2*c/m, t == 0]

sage: solve([f.integral(x,0,t) == 10], t)
[t == -(c + sqrt(c^2 + 20*m))/m, t == -(c - sqrt(c^2 + 20*m))/m]
2013-05-26 17:20:18 -0500 marked best answer Nice naming of variables with subscript or superscript, avoiding variable names like phi_jm1_np1 ($\phi_{j-1}^{n+1}$)

You might want to combine your variables into a tuple of tuples, or into a dictionary, and write

phi[j-1][n+1]

or

phi[j-1,n+1]
2013-05-26 17:20:18 -0500 received badge  Scholar (source)
2013-05-26 17:20:17 -0500 received badge  Supporter (source)
2013-05-23 22:28:24 -0500 asked a question Using solve() to find an unknown which is a limit of integration?

Is it possible to use the solve() function to find an unknown which is a limit of integration? A trivial example would be,

$$ \int_0^{x^\prime} mx+c \quad dx = 10 $$

where $x^{\prime}$ is the unknown ($m$ and $c$ are both known).

2013-04-08 06:52:29 -0500 received badge  Student (source)
2013-04-06 03:46:25 -0500 asked a question Nice naming of variables with subscript or superscript, avoiding variable names like phi_jm1_np1 ($\phi_{j-1}^{n+1}$)

In my worksheets I have many variables with subscripted/superscripted names like phi_jm1_np1, where the mathematical notation is simple, $\phi_{j-1}^{n+1}$. Is there a compact notation, or simply a better way, of dealing with subscripts and superscripts using sage?

2013-03-31 16:00:48 -0500 received badge  Editor (source)
2013-03-31 15:59:49 -0500 asked a question 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 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.