function lab4soln % where Name_XXXXXXX_hwN is the name of the file you submit without the extension .m %------------------------------------------------------------------------ %%% ENGINEERING MATHEMATICS IV - MATH 2ZZ3 %%% ASSIGNMENT #5: %%% TRIPLE INTEGRALS, DIVERGENCE THEOREM AND CHANGE OF VARIABLES %------------------------------------------------------------------------ %------------------------------------------------------------------------ % Covers: % - "Numerical Mathematics" by M. Grasselli and D. Pelinovsky, % Sections 7.7--7.8. % "Advanced Engineering Mathematics" by D.G. Zill and W.S. Wright, section 9.15, 9.16, 9.17 %------------------------------------------------------------------------ %------------------------------------------------------------------------ % Instructions: % - Submit your assignment electronically (via Email) to the % address specific to your last name as indicated on the course % website; hardcopy submissions will not be accepted. % - It is obligatory to use the current MATLAB template file available at % http://www.math.mcmaster.ca/gabardo/MATH2ZZ3/frames/template.m; % submissions non compliant with this template will not be accepted. % - Make sure to enter your name and student I.D. number in the % appropriate section of the template. % - Late submissions and submissions which do not comply with % these guidelines will not be accepted. % - All graphs should contain suitable titles and legends. %------------------------------------------------------------------------ % Written by Vladislav Bukshtynov, 2009 clc; close all; clear all; % Student information disp(' ------------ Student Information ------------ ') % Please enter your information here Name = 'Lab 4'; Surname = 'Solutions'; ID = 1234567; fprintf(' Student: %s %s (ID: %d) \n', Name, Surname, ID); disp(' ------------------------------------------------ ') disp(' ') disp(' ') disp(' ') disp(' ') disp(' ---------- Solution to Question #1 ---------- ') disp(' ') % (a) % reduce third order equation to first order system % the "y" here is actually the column vector [y''; y'; y] f = @(t,y) [2*t.^2+10*t+8; 0; 0] + [-4,5,-2; 1,0,0; 0,1,0]*y; % this was missing from the original problem a = 13; % the 3rd column of Y1, Y2, etc, is the approximate solution [T1,Y1] = ode23(f,[0 a],[3 -1 1]); [T2,Y2] = ode45(f,[0 a],[3 -1 1]); [T3,Y3] = ode113(f,[0 a],[3 -1 1]); [T4,Y4] = ode15s(f,[0 a],[3 -1 1]); figure('Name','Approximate solutions using 4 different solvers'); title({'Approximate solutions to:', ... 'y''''''+ 4y''''+5y''+2y = 2t^2+10t+8', ... 'y(0) = 1, y''(0) = -1, y''''(0) = 3'}); xlabel('t'); ylabel('y'); hold on; plot(T1,Y1(:,3),T2,Y2(:,3),T3,Y3(:,3),T4,Y4(:,3)); legend('ode23','ode45','ode113','ode15s'); legend('Location','NorthWest'); % (b) figure('Name','Timesteps used for 4 different solvers'); title({'Size of timesteps used by the indicated solvers in approximating solutions to', ... 'y''''''+ 4y''''+5y''+2y = 2t^2+10t+8', ... 'y(0) = 1, y''(0) = -1, y''''(0) = 3'}); xlabel('t'); ylabel('h (timestep)'); hold on; plot(T1(2:end),T1(2:end)-T1(1:end-1), ... T2(2:end),T2(2:end)-T2(1:end-1), ... T3(2:end),T3(2:end)-T3(1:end-1), ... T4(2:end),T4(2:end)-T4(1:end-1)); legend('ode23','ode45','ode113','ode15s'); legend('Location','NorthWest'); disp(' ') disp(' ------------------------------------------------ ') disp(' ') disp(' ') disp(' ') disp(' ') disp(' ---------- Answers ---------- ') disp(' ') % DO NOT TOUCH THIS PART (RESERVED FOR THE INSTRUCTOR'S USE) Name Surname ID % User's Functions Space is below --------------------------