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! | http://paste.lisp.org/+2Z5J
Channel:None
Paste contents:
Raw Source | XML | Display As
kill(all)$

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;
box(de);

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

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);
box(fde);
box(fbc);

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)$
box(A);

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.