% We are trying to find A that satisfies y(1) = 2 tspan = [0:.1:1]; alpha = -1; beta = 2; A = 1; y0 = [alpha A]; options = odeset('AbsTol',10^(-6)); % A has to be greater than alpha, so A > -1. % Begining with A = 1 we can move the value % of A to the right or to the left using bisection dA = 4; tol = 10^(-6); for j=1:1000 % Begin convergence loop [t,y] = ode45('f',tspan,y0,options); if (abs(y(end,1)-beta) < tol) % check for convergence break % get out of convergence loop end if (y(end,1) > beta) % this IF statement block checks to see if A needs to be higher or lower A=A-dA else dA=dA/2; A=A+dA end % y0 = [alpha A]; % Update initial conditions end % End convergence loop figure(1), plot(t,y(:,1),'g*-',tspan(1),alpha,'bs',tspan(end),beta, 'bo') % plot solution y set(gca,'FontSize',20) %Alternatively use bvp4c