function sol = prob_3_15(abstol,reltol) % % With input arguments I can play with the values of % the absolution and relative tolerances % % Written by: % -- % John L. Weatherwax 2005-04-18 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- bvpopts = bvpset( 'RelTol', reltol, 'AbsTol', abstol ); solinit = bvpinit(linspace(0,1,5),@guess); sol = bvp4c(@odes,@bcs,solinit,bvpopts); %plot(sol.x,sol.y(1,:)); %print -depsc ch3fig1a %figure xint = linspace(0,1,100); Sxint = deval(sol,xint); %plot(xint,Sxint(1,:)); %print -depsc ch3fig1b figure; res = Sxint(2,:).^2 + 2*1*(exp(Sxint(1,:))-1)-Sxint(2,1)^2; plot( xint, res, '-or' ); grid on; %================================================= function v = guess(x) v = [ x*(1-x); 1-2*x ]; function dydx = odes(x,y) dydx = [ y(2); -exp(y(1)) ]; function res = bcs(ya,yb) res = [ ya(1); yb(1) ];