$$ \newcommand{\uex}{{u_{\small\mbox{e}}}} \newcommand{\Aex}{{A_{\small\mbox{e}}}} \newcommand{\half}{\frac{1}{2}} \newcommand{\Oof}[1]{\mathcal{O}(#1)} $$

« Previous
Next »

Comparing with the exact solution

Python function for the exact solution \( \uex(t)=Ie^{-at} \):

def exact_solution(t, I, a):
    return I*exp(-a*t)

Quick plotting:

u_e = exact_solution(t, I, a)
plot(t, u, t, u_e)

Problem: \( \uex(t) \) applies the same mesh as \( u^n \) and looks as a piecewise linear function.

Remedy: Introduce a very fine mesh for \( \uex \).

t_e = linspace(0, T, 1001)      # fine mesh
u_e = exact_solution(t_e, I, a)

plot(t_e, u_e, 'b-',            # blue line for u_e
     t,   u,   'r--o')          # red dashes w/circles

« Previous
Next »