%% Homework Tips for Math 365
% These are the homework tips for doing Math 365 homework
%% #1 - Don't cut and paste from a PDF
% Do not cut and paste PDF text into your homework script. You run the
% risk of introducting hidden characters into your code or comments, and
% Publish may not work.
%% #2 - Don't hardcode numbers
% Do not "hardwire" approximations when Matlab can compute them to full
% precision.
%%
% *Example* Compute the area of a triangle wth sides A and B and
% enclosed angle theta :
theta = 10*pi/180;
hardwired = 0.1737; % Bad : Do not "hardcode" the value of the sin(th);
% this is what Matlab is for
sinth = sin(theta); % Good : Let Matlab compute the sin(th) for you.
A = 2;
B = 7;
Area = 0.5*A*B*sinth;
%%
% Especially don't "hardwire" numbers if
%
% * You don't tell me where your hardwired value came from.
%
% * You supply very few digits of a value that we know to full precision.
%
% * You don't indicate how accurate your value is. For example,
% you might get values from a CAD package, and report them to full
% precision. But in fact, there is no way that a CAD package can give you
% that much precision. Or if it does, you may well have been able to
% compute the same values in Matlab.
%
% Examples of the above errors are below.
% The exact area is
area_exact = 1.55678393345; % where did this come from?
% The value of e, obtained from my calculator is
e_const = 2.7183; % Much better to use e_const = exp(1)
% These numbers appear to be very "accurate", but who really knows?
x = [1.2348454366677766; 4.556667841225998]; % Really?
y = [4.5677445639358711; -2.345664448941219];
%%
% The obvious exceptions to this rule are when you are asked to supply
% phyiscal constants, such as the acceleration of gravity, or a thermal
% conductivity. In this case, you may only know the constant to a few
% digits.
g = 9.81; % m/s acceleration due to gravity
beta = 1.2e-4; % Thermal conductivity.
%% #3 - Formatting output
% Don't use the 'disp' command to show your results. Most likely, you
% won't show enough digits.
disp(Area)
%%
% Instead, use the 'write_file' function to save your results to a file.
% You can check the results in the file by using the 'type' command.
write_file(Area,'Area.out');
type Area.out
%% #4 - Line continuation
% Don't let your homework text exceed the 72 character limit. You can see
% this limit as a thin line near the right edge of the Matlab editor. Don't
% let your code or comments go past this line. To continue your code from
% one line to the next, use the '...' line continuation characters, as the
% example below shows.
x = [1,2,3,4,sin(10), linspace(1,100), rand(1,10), 100004, sin(56), ...
67.5678, atan(-1), sin(456.7)];
%% #5 - Typeset any explanatory text
% Typeset any explanatory text that explains your method, or a particular
% approach that you took. This example, this text is typeset (using,
% for example, a Times Roman font).
% This text is not typeset and will appear as a comment in the code.
%% #6 - Publish your own code
% You can make sure that your code publishes using the command
%
% file = publish('homework_tips.m','pdf');
% open(file);
%
% THis is exactly what I will be grading, so be sure your code runs.