%Example 7.6, page 371
sstar1=fzero(@Ffun1,[-1,0])%interval is chosen by trial-error
%use sstar as the initial condition to solve the BVP
a=0;b=1;ya=1; %boundary conditions
dydt=@(t,y) [y(2);4*y(1)]; %define ODE system
[t,y]=ode45(dydt,[a,b],[ya;sstar1]); %solve ODE IVP
subplot(1,2,1)
plot(t,y(:,1),'-o');%only plot y(x) as the solution
xlabel('x');ylabel('y'); title('Example 7.6');

%Example 7.7, page 371
sstar2=fzero(@Ffun2,1)%interval is chosen by trial-error
%use sstar as the initial condition to solve the BVP
a=1;b=2;ya=0; %boundary conditions
dydt=@(t,y) [(4-2*y(2))/t^3;-exp(y(1))]; %define ODE system
[t,y]=ode45(dydt,[a,b],[ya;sstar2]); %solve ODE IVP
subplot(1,2,2)
plot(t,y(:,1),'-o');%only plot y(x) as the solution
xlabel('x');ylabel('y');title('Example 7.7');

function z=Ffun1(s)
a=0;b=1;ya=1;yb=3; %boundary conditions
dydt=@(t,y) [y(2);4*y(1)]; %define ODE system
[t,y]=ode45(dydt,[a,b],[ya;s]); %solve ODE IVP
%notice this example has boundary condition y_1(1)=3;
z=y(end,1)-yb;%compute the final value difference
end

function z=Ffun2(s)
a=1;b=2;ya=0;yb=0; %boundary conditions
dydt=@(t,y) [(4-2*y(2))/t^3;-exp(y(1))]; %define ODE system
[t,y]=ode45(dydt,[a,b],[ya;s]); %solve ODE IVP
%notice this example has boundary condition y_2(2)=0;
z=y(end,2)-yb;%compute the final value difference
end