function lab1soln %------------------------------------------------------------------------ %%% 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 1'; 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) x = linspace(0,3,10); y = x; [X,Y] = meshgrid(x,y); scrsz = get(0,'ScreenSize'); figure('Name','Direction field and solutions for y'' = x^2/y^2', ... 'OuterPosition',[1 scrsz(4)/3 2*scrsz(3)/3 2*scrsz(4)/3]); hold on; grid on; title('Direction field and solutions for y'' = x^2/y^2'); quiver(X,Y,Y.^2,X.^2,'Color','black'); xlim([0 3]); ylim([0 3]); % (b) x = linspace(0,3,102); x1 = linspace(1,3,67); % for the solution through (0,-1) y1 = (x1-1).^(1/3); x2 = linspace(2,3,34); % for the solution through (0,-2) plot(x,(x.^3+8).^(1/3), ... % (0,2) x,(x.^3+1).^(1/3), ... % (0,1) x,x, ... % (0,0) x1,(x1.^3-1).^(1/3), ... % (0,-1) x2,(x2.^3-8).^(1/3)); % (0,-2) legend('direction field','soln through (0,2)', 'soln through (0,1)' , ... 'soln through (0,0)', 'soln through (0,-1)', 'soln through (0,-2)'); legend('Location','EastOutside'); disp(' ') disp(' ------------------------------------------------ ') disp(' ') disp(' ') disp(' ') disp(' ') disp(' ---------- Solution to Question #2 ---------- ') disp(' ') syms xs; fs = exp(-xs) - xs; % because I'm lazy to compute the derivative by hand: f = matlabFunction(fs); fp = matlabFunction(diff(fs,xs)); % fake "do ... while" loop new = 1; test = true; while test old = new; new = old - f(old)/fp(old); test = abs(new - old) >= 10^(-5); end Answer1 = new; disp(' ') disp(' ------------------------------------------------ ') disp(' ') disp(' ') disp(' ') disp(' ') disp(' ---------- Answers ---------- ') disp(' ') % DO NOT TOUCH THIS PART (RESERVED FOR THE INSTRUCTOR'S USE) Name Surname ID Answer1 % User's Functions Space is below --------------------------