% Sample driver for Linear Shooting method as we saw in class (Problem 1)
% You need to update the problem data and implement linshoot.m
% 11.1.3 a
fprintf('------------ 11.1.3 a -------------\n');
f = @(t,y,yp) -3*yp +2*y+2*t+3; 
a=0; b=1; alpha=2; beta=1; n=10; h=(b-a)/n;
y = linshoot(a,b,n,alpha,beta,f);
% true solution is not needed, but is included here for reference
% (computed using Maple)
ytrue=@(x) -5*exp((1/2*(-3+sqrt(17)))*x)*(-1+exp(-3/2-(1/2)*sqrt(17)))/(exp(-3/2+(1/2)*sqrt(17))-exp(-3/2-(1/2)*sqrt(17)))+5*exp(-(1/2*(3+sqrt(17)))*x)*(-1+exp(-3/2+(1/2)*sqrt(17)))/(exp(-3/2+(1/2)*sqrt(17))-exp(-3/2-(1/2)*sqrt(17)))-3-x;
fprintf('%3s %11s %11s\n','t','y','y true');
for i=2:n+1,
 ti=a+(i-1)*h;
 fprintf('%3.1f %11.8f %11.8f\n',ti,y(i),ytrue(ti));
end;

% 11.1.3 c
fprintf('------------ 11.1.3 c -------------\n');
f = @(t,y,yp) -(t+1)*yp + 2*y + (1-t^2)*exp(-t);
a=0;b=1; alpha=-1; beta=0; n=10; h=(b-a)/n;
y = linshoot(a,b,n,alpha,beta,f);
% true solution is not needed, but is included here for reference
% (computed using Maple)
ytrue = @(x) 2+2*x+x^2+2*(-1-(1/2)*x^2-x)+(-1+x)*exp(-x);
fprintf('%4s %11s %11s\n','t','y','ytrue');
for i=1:n+1,
 ti=a+(i-1)*h;
 fprintf('%4.2f %11.8f %11.8f\n',ti,y(i),ytrue(ti));
end;

% Typical output
%
%   >> prob1_sample
%   ------------ 11.1.3 a -------------
%     t           y      y true
%   0.1  1.40843171  1.40834155
%   0.2  1.02226375  1.02214040
%   0.3  0.78331775  0.78319232
%   0.4  0.65103904  0.65092714
%   0.5  0.59722789  0.59713617
%   0.6  0.60234998  0.60228009
%   0.7  0.65295283  0.65290384
%   0.8  0.73985699  0.73982679
%   0.9  0.85688993  0.85687604
%   1.0  1.00000000  1.00000000
%   ------------ 11.1.3 c -------------
%      t           y       ytrue
%   0.00 -1.00000000 -1.00000000
%   0.10 -0.81435498 -0.81435368
%   0.20 -0.65498676 -0.65498460
%   0.30 -0.51857538 -0.51857275
%   0.40 -0.40219481 -0.40219203
%   0.50 -0.30326802 -0.30326533
%   0.60 -0.21952705 -0.21952465
%   0.70 -0.14897754 -0.14897559
%   0.80 -0.08986717 -0.08986579
%   0.90 -0.04065769 -0.04065697
%   1.00  0.00000000  0.00000000
