Exercise 10.6.1

For each linear BVP, use fem to solve and plot the solution for n=40. Then for each n=10,20,40,...640, compute the norm of the error. Make a log-log convergence plot fo error versus n and compare graphically to second-order convergence.

u Exact solution: x^2(4-x^2).

c = x -> 1; # second derivative negative ?? 1 or x?
s = x -> 1; # function
f = x -> -8 + 16*x^2 - x^4; #output

x,u = FNC.fem(c,s,f,0,2,40);
plot(x,u,label="",
    xaxis=(L"x"),yaxis=(L"u"),title="Solution by finite elements")
exact = x -> (x^2)*(4-x^2);

n = [10*(2^(i-1)) for i = 1:7];

err = zeros(size(n));

for (k,n) in enumerate(n)
  x,u = FNC.fem(c,s,f,0,2,n)
  err[k] = norm(exact.(x)-u, Inf)
end

plot(n, err, m=:o);
plot!(n,10*10*n.^(-2),l=(:dash,:gray),label="2nd order",
    xaxis=(:log10,"n"), yaxis=(:log10,"max error"),
    title="Convergence of Finite Element Method")