% % 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. % %----- close all; clc; clear; % set the constants of this problem: u0 = 1.; x0 = 0.5; % the constant x sub 0 n = 2; a = 0.015; b = 0.01; c = 0; % the times and initial conditions: t_0 = 0.; t_f = 10.; x_0_ic = 0.4; % the initial conditions on x(t) % find the optimal value for the initial condition for lambda(t) or lambda_0 so that lambda(t_f) matches the known boundary: % lambda_0 = fminsearch( @(x) sect_4_prob_2_J_min_fn(x, t_0,t_f,x_0_ic, u0,x0,n,a,b,c), [ -10. ] ) % evaluate J at this value of lambda_0: % sect_4_prob_2_J_min_fn(lambda_0, t_0,t_f,x_0_ic, u0,x0,n,a,b,c) % plot the state x(t) and the control u(t): % sol = ode23s( @(t,x) sect_4_prob_2_J_ode_fn(t,x, u0,x0,n,a,b,c), [t_0,t_f], [lambda_0;x_0_ic] ); t = sol.x; lambda = sol.y(1,:); x = sol.y(2,:); figure; plot( t, x, '-o' ); xlabel('time'); ylabel('x(t)'); %saveas( gcf, '../../WriteUp/Graphics/Chapter3/sect_4_prob_2_x_t.eps', 'epsc' ); figure; plot( t, lambda, '-o' ); xlabel('time'); ylabel('lambda(t)'); u = sect_4_prob_2_u_from_x_N_lambda(t,x,lambda, u0,x0,n,a,b,c); figure; plot( t, u, '-o' ); xlabel('time'); ylabel('u(t)'); %saveas( gcf, '../../WriteUp/Graphics/Chapter3/sect_4_prob_2_u_t.eps', 'epsc' );