function [J] = sect_3_prob_2_part_e_J_min_fn(alpha_0, alpha_1, t_0, t_f, v_0, gamma_0, h_0, gamma_d, h_d, d_gamma, d_h) % % Written by: % -- % John L. Weatherwax 2006-08-28 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- % First integate the given differential equations from t=0 to t=t_f: % sol = ode45( @(t,x) sect_3_prob_2_part_e_J_ode_fn(t,x, alpha_0,alpha_1), [t_0,t_f], [v_0;gamma_0;h_0] ); gamma_t = sol.y(2,:); % extract gamma(t) h_t = sol.y(3,:); % extrat h(t) % Second evaluate the expression for J: % J_part1 = d_gamma * ( gamma_t(end) - gamma_d )^2; J_part2 = d_h * ( h_t(end) - h_d )^2; % we have a error term that depends on how well we match the final end point J_part3 = alpha_0^2 * t_f + alpha_0 * alpha_1 * t_f^2 + ( alpha_1^2 ) * t_f^3 / 3.0; J = 0.5 * ( J_part1 + J_part2 + J_part3 );