function [J] = sect_3_prob_4_J_min_fn(alpha, T, t_0, t_f, ... v_0, gamma_0, h_0, ... % initial conditions v_d, gamma_d, h_d, ... % desired end point conditions q_v, q_gamma, q_h, r_1, r_2) % scale factors to weight different parts of J % % 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_4_J_ode_fn(t,x, alpha,T), [t_0,t_f], [v_0;gamma_0;h_0] ); v_t = sol.y(1,:); gamma_t = sol.y(2,:); % extract gamma(t) h_t = sol.y(3,:); % Second evaluate the expression for J: % J_part1 = q_v * ( v_t(end) - v_d )^2; J_part2 = q_gamma * ( gamma_t(end) - gamma_d )^2; J_part3 = q_h * ( h_t(end) - h_d )^2; J_part4 = r_1 * alpha^2 * t_f + r_2 * T^2 * t_f; J = 0.5 * ( J_part1 + J_part2 + J_part3 + J_part4 );