function [J] = sect_3_prob_5_J_min_fn(c_1, c_2, t_0, t_f, ... x_1d, ... % desired end point conditions q, r, omega_n, xi) % 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_5_J_ode_fn(t,x, c_1,c_2, omega_n,xi,x_1d), [t_0,t_f], [0;0] ); t_t = sol.x; x_1t = sol.y(1,:); % extract x_1(t) x_2t = sol.y(2,:); u_t = -c_1 * ( x_1t - x_1d ) - c_2 * x_2t; % compute u(t) % Second evaluate the expression for J: % J_part1 = q * ( x_1t(end) - x_1d )^2; J_part2 = r * trapz( t_t, u_t.^2 ); J = 0.5 * ( J_part1 + J_part2 );