x_e = linspace(0,2);
C1 = exp(-4)/(1+exp(-4)); C2 = C1*exp(4);
f_e = C1*exp(x_e) + C2*exp(-x_e);
plot(x_e, f_e); xlabel("x"); ylabel("f(x)");
pkg load odepkg;
fun = @(x,y) [ y(2); y(1) ];
bc = @(ya, yb) [ya(1)-1; yb(2)];
xd = linspace(0, 2, 10);
ya = zeros(2, length(xd));
solinit.x = xd; solinit.y=ya;
res = bvp4c(fun, bc, solinit);
plot(res.x, res.y(1,:), "-;f(x);",res.x, res.yp(1,:), "-;f'(x);"); hold on; line(xlim, [0 0]); hold off;
fun = @(x,y) [ y(2); 2*y(1)-2*y(2)-3];
bc = @(ya, yb) [ya(1)-1; yb(1)+2];
xd = linspace(0, 2, 10);
ya = zeros(2, length(xd));
solinit.x = xd; solinit.y=ya;
res = bvp4c(fun, bc, solinit);
AbsErr = 0.94892 RelErr = 0.059077 Nint = 18 AbsErr = 0.42276 RelErr = 0.014300 Nint = 36 AbsErr = 0.19801 RelErr = 0.0035005 Nint = 72 AbsErr = 0.095601 RelErr = 0.00086465
plot(res.x, res.y(1,:), "-;f(x);",res.x, res.yp(1,:), "-;f'(x);"); hold on; line(xlim, [0 0]); hold off;