% This script illustrates the use of the function bvpsolve to solve 
% linear 2-point BVPs of the form
% y''(t) = u(t) + v(t)*y(t) + w(t)*y'(t)
% with BCs y(a) = alpha, y(b) = beta
clear all
clc
close all
warning off
scrnsz = get(0, 'Screensize');

u = inline('2./(1+t.^2) - log(1+t.^2)');
v = inline('ones(size(t))');
w = inline('-2.*t./(1+t.^2)');

a = 0;
b = 1;
alpha = 0;
beta = log(2);
m = 39;

[t,y] = bvpsolve(u,v,w,a,b,alpha,beta,m);

% exact solution
tt = linspace(a,b,100);
yy = log(1+tt.^2);

% plot both together
figure('Position', [5 10 scrnsz(3)-5 scrnsz(4)-60])
hold on
plot(t,y,'r')
plot(tt,yy,'g')
hold off

