% % Written by: % -- % John L. Weatherwax 2009-04-21 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- addpath('../../BookCode'); close all; clc; clear; % Problem EPage 118; Shooting method on EPage 106; % s = -3.0:0.5:2.0; % evalute the value of y(1) at each of these slopes at zero i.e. y'(0) (we want y(1) ~ 2) ncases = length(s); b = zeros(1,ncases); for i=1:ncases, [x,y] = ode45( 'c_6_p_2_ode_fn', [0, 1], [1, s(i)] ); [m,n] = size(y); b(1,i) = y(m,1); % save the value of y(1) for this slope end s0 = aitken(b,s,2); % use aitken's method to find the slope that gives y(1) == 2 [x,y] = ode45( 'c_6_p_2_ode_fn', [0, 1], [1, s0] ); plot( x, y(:,1), '-k' ); hold('on'); grid('on'); % Use the function "twopoint.m": % n = 10; x = linspace( 0, 1, n+1 ); C = ones( 1, n+1 ); D = ones( 1, n+1 ); E = -6 * ones( 1, n+1 ); F = zeros( 1, n+1 ); y_tp = twopoint( x, C, D, E, F, 1, 1, 1, 2 ); plot( x, y_tp, '-b' ); xs = linspace( 0, 1, 100 ); ys = 0.2657 * exp( 2*xs ) + 0.7343 * exp( -3*xs ); plot( xs, ys, '-g' ); legend( 'shooting method', 'twopoint', 'truth', 'location', 'best' ); %saveas( gcf, '../../WriteUp/Graphics/Chapter6/c_6_p_2_plot.eps', 'epsc' );