function [t,T] = dao(alpha,delta,tf) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Course: APPM 2360 % Author: James Robinson % Date: Febuaury 2007 % % WARNING: Do not change any of the code in this file while working on % your lab assignment. % % Description: This function numerically solves the delayed difference % model for the Niņo 3 temperature anomaly used in the El Niņo lab (T'=T-T^3-alpha*T(t-delta)). % The solution is computed using Matlab's dde23 function. The solution always starts at % t=0, and the intial data from t=-delta to t=0 is given by the subfunction % Thist. % % Input: % alpha Constant in equation % delta Time delay % tf The solver will produce a solution from t=0 to t=tf. % % Output: % t The vector of time values at which T is calculated. % T A vector of Niņo 3 temperature anomaly values. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Code for dao %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Call dde23 to solve the equation with the given constants. sol = dde23(@dTdt,delta,@Thist,[0 tf],[],alpha,delta); % Set the outputs to the appropriate values from the solution structure. t = sol.x; T = sol.y; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Subfunctions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function T = Thist(t,alpha,delta) %This function provides intial values for T from T=-delta to T=0. T = -2-0.1*sin(2*pi*delta*t); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function Tp = dTdt(t,T,Z,alpha,delta) % This function calculates the first derivative of T with respect to t. Tp = T-T.^3-alpha*Z; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%