Paste number 138871: Finite differences in Maxima

Paste number 138871: Finite differences in Maxima
Pasted by: jmbr
When:7 years, 1 week ago
Share:Tweet this! |
Paste contents:
Raw Source | XML | Display As

depends([D, p], x)$
depends([u, v], [x, t])$

flux: D*p*'diff(u/p, x)$
de1: 'diff(u, t) = 'diff(flux, x)$
de: de1/p, u = p*v, diff, expand;

bc: 'diff(v, x) = 0;

discretization: [diff(v, t) = (v[i, j+1] - v[i, j])/k,
                 diff(v, x, 2) = (v[i-1, j+1] -2*v[i, j+1] + v[i+1, j+1])/h^2,
                 diff(v, x) = (v[i+1, j+1] - v[i-1, j+1])/(2*h),
                 diff(p, x) = (p[i+1] - p[i-1])/(2*h),
                 diff(D, x) = (D[i+1] - D[i-1])/(2*h),
                 D = D[i],
                 p = 1/2*(p[i-1]+p[i+1])];

fde: psubst(discretization, de);
fbc: psubst(discretization, bc);

indets: makelist(v[l, j+1], l, [i-1, i, i+1])$
indets1: [v[1, j+1], v[2, j+1]]$
indetsN: [v[N-1, j+1], v[N, j+1]]$

bnd1: first(solve(subst(i = 1, fbc), v[0, j+1]))$
bndN: first(solve(subst(i = N, fbc), v[N+1, j+1]))$

M: augcoefmatrix([subst([i = 1, bnd1], fde), fde, subst([i = N, bndN], fde)],
                 append(indets1, indets, indetsN))$
A: expand(M*k)$

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.