function template2
% Assignment #2
%----------------------------------------------------------------------%%%
ENGINEERING MATHEMATICS IV - MATH 2Z03
%%%
Assignment #2
%%%
VECTOR FIELDS
%----------------------------------------------------------------------%----------------------------------------------------------------------% Covers:
% - "Advanced Engineering Mathematics" by D.G. Zill and W.S. Wright,
%
(Jones and Bartlett, 5th edition) Sections 9.1-9.3
%
% - "Numerical Mathematics" by M. Grasselli and D. Pelinovsky
%
(Jones and Bartlett, 2008), sections 7.4-7.4
%----------------------------------------------------------------------% McMaster Policy on Academic Integrity:
% ======================================
% You are expected to exhibit honesty and use ethical behaviour in all
% aspects of the learning process. Academic credentials you earn are
% rooted in principles of honesty and academic integrity.
%
% Academic dishonesty is to knowingly act or fail to act in a way that
% results or could result in unearned academic credit or advantage. This
% behaviour can result in serious consequences e.g., the grade of zero
on
% an assignment, loss of credit with a notation on the transcript
% (notation reads: "Grade of F assigned for academic dishonesty"),
and/or
% suspension or expulsion from the university. It is your responsibility
% to understand what constitutes academic dishonesty. For information
% on the various types of academic dishonesty, please refer to the
Academic
% Integrity Policy, located at:
%
www.mcmaster.ca/academicintegrity
%
% The following illustrates only three forms of academic dishonesty:
%
1) Plagiarism e.g., the submission of work that is not ones own or
%
for which other credit has been obtained.
%
2) Improper collaboration in group work.
%
3) Copying or using unauthorized aids in tests and examinations.
%----------------------------------------------------------------------% Instructions:
% - Upload your assignment electronically using the web address
%
provided on Avenue (you can log in using you MacID and following the
%
instructions on the log-in screen). Please note that:
%
* you can submit your Matlab assignment a maximum of 5 times and
%
only your most recent submission will be marked,
%
* the file submitted must have extension ".m",
%
* a confirmation Email will be sent to your McMaster Email address
%
and to any other address you provide during submission;
%
please check this message to make sure the correct file has
%
been submitted.
% - It is obligatory to use the current MATLAB template file available
%
from the course website on Avenue to Learn
% - Failure to type fresh code into the template code result in
%
charges of academic dishonesty
%
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.
%----------------------------------------------------------------------%
%
COPYING CODE FROM ANY OTHER STUDENT IS AN ACT OF ACADEMIC DISHONESTY
%
AND WILL BE DEALT WITH IN KEEPING WITH THE POLICIES OF THE
UNIVERSITY
%
%----------------------------------------------------------------------% Adapted from code written by Vladislav Bukshtynov
clc; close all; clear all;
% Student information
disp('
------------
Student Information
------------
')
% Please enter your information here
Name = 'Johny';
Surname = 'Good';
ID = 123456789;
fprintf('
disp('
disp('
disp('
disp('
disp('
Student:
%s %s (ID: %d) \n', Name, Surname, ID);
-----------------------------------------------')
')
')
')
')
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)
[x,y]=meshgrid(-1:0.02:1,-1:0.02:1);
z = 3*(1-3*x).^2.*exp(-(9*x.^2) - (3*y+1).^2) ...
- 10*(3*x/5 - 27*x.^3 - 243*y.^5).*exp(-9*x.^2-9*y.^2) ...
- 1/3*exp(-(3*x+1).^2 - 9*y.^2) + 1.0*(x.^2+y.^2) - 1.0;
contourf(x,y,z,20);
colorbar
colormap('default')
title('figure(1)')
hold on
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)
[x,y] = meshgrid(-1:0.2:1,-1:0.2:1);
fx = 2*exp(-9*x^2-6*x-(3*y+1)^2)*(x*exp(9*x^2+6*x+(3*y+1)^2)3*exp(6*x+6*y+1)*(810*x^4-153*x^2+7290*x*y^5+1)-9*exp(6*x)*(27*x^318*x^2+1)+(3*x+1)*exp(6*y));
fy = 2*(6075*y^4*exp(-9*(x^2+y^2))-9*(1-3*x)^2*(3*y+1)*exp(-9*x^2(3*y+1)^2)-54*y*exp(-9*(x^2+y^2))*(45*x^3-x+405*y^5)+3*y*exp(-(3*x+1)^29*y^2)+y);
figure(1)
quiver(x,y,fx,fy);
disp('
disp('
disp('
disp('
disp('
disp('
')
-----------------------------------------------')
')
')
')
disp(' ---------Solution to Question #3 ---------disp(' ')
% Insert here your solution to Question #3
% (if you define your own functions, they may appear
% at the end of the file)
disp('
disp('
disp('
disp('
disp('
disp('
')
-----------------------------------------------')
')
')
')
disp(' ---------Solution to Question #4
disp(' ')
% Insert here your solution to Question #4
----------
')
')
')
')
% (if you define your own functions, they may appear
% at the end of the file)
disp('
disp('
disp('
disp('
disp('
disp('
')
-----------------------------------------------')
')
')
')
disp(' ---------Solution to Question #5 ---------disp(' ')
% Insert here your solution to Question #5
% (if you define your own functions, they may appear
% at the end of the file)
disp('
disp('
disp('
disp('
disp('
disp('
')
-----------------------------------------------')
')
')
')
disp(' ---------Solution to Question #6 ---------disp(' ')
% Insert here your solution to Question #6
% (if you define your own functions, they may appear
% at the end of the file)
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
% You can add your own user-defined functions below
function [z] = fun(x,y)
z =
3*(1-3*x).^2.*exp(-(9*x.^2) - (3*y+1).^2) ...
- 10*(3*x/5 - 27*x.^3 - 243*y.^5).*exp(-9*x.^2-9*y.^2) ...
- 1/3*exp(-(3*x+1).^2 - 9*y.^2) + 1.0*(x.^2+y.^2) - 1.0;
% End of Assignment #2