% % 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: t_0 = 0.; t_f = 12.; xair = 45; xd = 70; x0 = 45; % the initial conditions on x_1(t) T = 4; k1 = 1.0; % first solve for mu: num = ( xd - ( xair + (x0 - xair)*exp( -(t_f - t_0)/T ) ) ); den = -( (k1^2)*T )*( 1 + exp( - 2*(t_f - t_0)/T ) )/4; mu = num/den; % integrate the dynamical equations (we have the explicit expression for x_1(t) so the ODE integration is not necessarily needed): sol = ode45( @(t,x) sect_5_prob_3_ode_fn(t,x, t_f,T,xair,k1,mu), [t_0,t_f], [x0] ); t = sol.x; % plot the solution x(t): figure; plot( t, sol.y, '-x' ); xlabel('time'), ylabel('x_1(t)'); title('state') %saveas( gcf, '../../WriteUp/Graphics/Chapter3/sect_5_prob_3_x_t.eps', 'epsc' ); % plot the control u(t): u = -mu*(k1/2)*exp( (t-t_f)/T ); figure; plot( t, u, '-o' ); xlabel('time'); ylabel('u'); title('control'); %saveas( gcf, '../../WriteUp/Graphics/Chapter3/sect_5_prob_3_u_t.eps', 'epsc' );