% Coded by NFR 4.25.19 % This code solves a boundary value (linear equation) ODE % span = [0 20]; y0 = [5 2]; % The second value is a guess for the inital value of Z [tp, yp] = ode45(@dydt,span,y0); CheckVal1 = yp(end,1) y0 = [5 -1]; % The second value is a second guess for the inital value of Z [tp, yp] = ode45(@dydt,span,y0); CheckVal2 = yp(end,1) % Interpolation - see equation 24.11 Slope = (-1-2)/(CheckVal2-CheckVal1); Zinterp = Slope*(8-CheckVal1)+2; % Use the interpolated value of z to get your solution y0 = [5 Zinterp]; % The second value is a second guess for the inital value of Z [tp, yp] = ode45(@dydt,span,y0); CheckVal3 = yp(end,1) function dy = dydt(t,y) % t = x, y(1) = y, y(2) = z dy = [y(2); (2*y(2)+y(1)-t)/7]; end