function Name_XXXXXXX_hwN %insert the exact file name (as explained in the submission % instructions) after "function" %------------------------------------------------------------------------ %%% ENGINEERING MATHEMATICS III - MATH 2Z03 %%% ASSIGNMENT #5 %%% HOMOGENEOUS SYSTEMS OF LINEAR ODEs %------------------------------------------------------------------------ %------------------------------------------------------------------------ % Covers: % - "Numerical Mathematics" by M. Grasselli and D. Pelinovsky, % Sections 1.6, 5.6, 9.2. % - "Advanced Engineering Mathematics" by D.G. Zill and W.S. Wright, % (Jones and Bartlett, 4th edition) Section 10.2. %------------------------------------------------------------------------ %------------------------------------------------------------------------ % Instructions: % - Submit your assignment electronically (via Email) to the % address specific to your lab section 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/M2Z03/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 = 'Johny'; Surname = 'Good'; ID = 123456789; fprintf(' Student: %s %s (ID: %d) \n', Name, Surname, ID); disp(' ------------------------------------------------ ') disp(' ') disp(' ') disp(' ') disp(' ') disp(' ---------- Solution to Question #1 ---------- ') disp(' ') % Insert here your solution to Question #1 % (if you define your own functions, they may appear % at the end of the file) a=6;b=7;c=8;d=9; A=[-(1+a/10), -(10+b);10+c, -(1+1/10)] Answer1=eig(A)' [r,p]=eig(A) in=[real(p(1,1));imag(p(1,1))]; B=[in, real(r(:,1)), imag(r(:,1))] ; Answer2=B x0(:,1)=[1;-1]; x0(:,2)=[-1;-1]; D=[real(r(:,1)), imag(r(:,1))]; C=D^(-1)*x0 Answer3=C t=[0:0.01:5]; for i=1:501 x(:,i)=exp(B(1,1)*t(i)).*( ( cos(B(2,1)*t(i)).*B(:,2)-sin(B(2,1)*t(i)).*B(:,3) ).*C(1,1) + (sin(B(2,1)*t(i)).*B(:,2)+cos(B(2,1)*t(i)).*B(:,3)).*C(2,1) ); u(:,i)=exp(B(1,1)*t(i)).*( ( cos(B(2,1)*t(i)).*B(:,2)-sin(B(2,1)*t(i)).*B(:,3) ).*C(1,2) + (sin(B(2,1)*t(i)).*B(:,2)+cos(B(2,1)*t(i)).*B(:,3)).*C(2,2) ); end figure grid on; plot(x(1,:), x(2,:), u(1,:), u(2,:)) grid on; xlabel('x'); ylabel('y'); disp(' ') disp(' ------------------------------------------------ ') disp(' ') disp(' ') disp(' ') disp(' ') disp(' ---------- Solution to Question #2 ---------- ') disp(' ') % Insert here your solution to Question #2 % (if you define your own functions, they may appear % at the end of the file) A=[1 2+a/10; 4+b/10 -1]; [r,p]=eig(A) h=0.01; Answer4=[p(1,1),p(2,2)]; xmax=10; ymax=10; j=1; Xforward(:,1)=[1;0]; while (abs(Xforward(1,j))<= xmax) & (abs(Xforward(2,j))<=ymax) Xforward(:,j+1)=Xforward(:,j)+h.*A*Xforward(:,j); j=j+1; end Xbackward(:,1)=[1;0]; k=1; while (abs(Xbackward(1,k))<= xmax) & (abs(Xbackward(2,k))<=ymax) Xbackward(:,k+1)=Xbackward(:,k)-h.*A*Xbackward(:,k); k=k+1; end j=1; Yforward(:,1)=[-1;0]; while (abs(Yforward(1,j))<= xmax) & (abs(Yforward(2,j))<=ymax) Yforward(:,j+1)=Yforward(:,j)+h.*A*Yforward(:,j); j=j+1; end Ybackward(:,1)=[-1;0]; k=1; while (abs(Ybackward(1,k))<= xmax) & (abs(Ybackward(2,k))<=ymax) Ybackward(:,k+1)=Ybackward(:,k)-h.*A*Ybackward(:,k); k=k+1; end j=1; Uforward(:,1)=[0;1]; while (abs(Uforward(1,j))<= xmax) & (abs(Uforward(2,j))<=ymax) Uforward(:,j+1)=Uforward(:,j)+h.*A*Uforward(:,j); j=j+1; end Ubackward(:,1)=[0;1]; k=1; while (abs(Ubackward(1,k))<= xmax) & (abs(Ubackward(2,k))<=ymax) Ubackward(:,k+1)=Ubackward(:,k)-h.*A*Ubackward(:,k); k=k+1; end j=1; Tforward(:,1)=[0;-1]; while (abs(Tforward(1,j))<= xmax) & (abs(Tforward(2,j))<=ymax) Tforward(:,j+1)=Tforward(:,j)+h.*A*Tforward(:,j); j=j+1; end Tbackward(:,1)=[0;-1]; k=1; while (abs(Tbackward(1,k))<= xmax) & (abs(Tbackward(2,k))<=ymax) Tbackward(:,k+1)=Tbackward(:,k)-h.*A*Tbackward(:,k); k=k+1; end figure; hold on; grid on; plot(Xforward(1,:),Xforward(2,:),'blue') plot(Xbackward(1,:),Xbackward(2,:),'blue') plot(Yforward(1,:),Yforward(2,:),'green') plot(Ybackward(1,:),Ybackward(2,:),'green') plot(Uforward(1,:),Uforward(2,:),'red') plot(Ubackward(1,:),Ubackward(2,:),'red') plot(Tforward(1,:),Tforward(2,:),'yellow') plot(Tbackward(1,:),Tbackward(2,:),'yellow') Eig1for(:,1)=[0;0]; i=1; while (abs(Eig1for(1,i))<= xmax) & (abs(Eig1for(2,i))<=ymax) Eig1for(:,i+1)=i.*r(:,1)*h; i=i+1; end Eig1back(:,1)=[0;0]; j=1; while (abs(Eig1back(1,j))<= xmax) & (abs(Eig1back(2,j))<=ymax) Eig1back(:,j+1)=-j.*r(:,1)*h; j=j+1; end plot(Eig1for(1,:),Eig1for(2,:), 'black') plot(Eig1back(1,:),Eig1back(2,:), 'black') Eig2for(:,1)=[0;0]; i=1; while (abs(Eig2for(1,i))<= xmax) & (abs(Eig2for(2,i))<=ymax) Eig2for(:,i+1)=i.*r(:,2)*h; i=i+1; end Eig2back(:,1)=[0;0]; j=1; while (abs(Eig2back(2,j))<= xmax) & (abs(Eig2back(2,j))<=ymax) Eig2back(:,j+1)=-j.*r(:,2)*h; j=j+1; end plot(Eig2for(1,:),Eig2for(2,:), 'black') plot(Eig2back(1,:),Eig2back(2,:), 'black') disp(' ') disp(' ------------------------------------------------ ') disp(' ') disp(' ') disp(' ') disp(' ') disp(' ---------- Answers ---------- ') disp(' ') % DO NOT TOUCH THIS PART (RESERVED FOR THE INSTRUCTOR'S USE) Name Surname ID Answer1 Answer2 Answer3 Answer4 % You can add your own user-defined functions below