Exercise 10.4.5
The Airy equation is u″. Its solution is exponential for x>0 and oscillatory for x<0. The exact solution is given by u = c_1\textrm{Ai}(x) + c_2\textrm{Bi}(x), where Ai and Bi are Airy functions (airyai
and airybi
in julia).
- Suppose that u(-10) = -1, u(2) = 1. By setting up and solving a 2 \times 2 linear system, find the numerical values for c_1 and c_2. Plot resulting exact solution
x = [-10; 2];
b = [-1; 1];
L = [airyai.(x) airybi.(x)];
c = L \ b;
exact = x -> c[1]*airyai(x) + c[2]*airybi(x);
plot(exact, -10, 2, title = "2x2 solution")
- Use
bvplin
with n = 120 to find the solution with the boudnary conditions in (a). In a 2-by-1 subplot array, plot the finite-difference solution and its error.
p = x -> 0; # first derivative
q = x -> -x; # function
r = x -> 0; # output
x,u = FNC.bvplin(p,q,r,[-10,2], -1, 1, 120);
plot(exact, -10, 2,layout=(2,1),label="exact");
scatter!(x,u,m=:o,subplot=1,label="numerical",
yaxis=("solution"),title="Solution of a linear BVP");
plot!(x,exact.(x)-u,subplot=2,xaxis=L"x",yaxis=("error"))
- repeat with n = 800
p = x -> 0; # first derivative
q = x -> -x; # function
r = x -> 0; # output
x,u = FNC.bvplin(p,q,r,[-10,2], -1, 1, 800);
plot(exact, -10, 2,layout=(2,1),label="exact");
scatter!(x,u,m=:o,subplot=1,label="numerical",
yaxis=("solution"),title="Solution of a linear BVP");
plot!(x,exact.(x)-u,subplot=2,xaxis=L"x",yaxis=("error"))