Submitting Assignments with MATLAB
AMSC/CMSC 460 - Spring 2018


Many of the homework assignment will require a MATLAB component. Please be sure they are done correctly.

  • You must write at least one m-file for each problem. (Typing commands at the >> prompt and printing this out is not allowed)
  • To submit a problem with MATLAB you must submit the m-file along with the generated output and images. This can be done using the Publish to HTML feature in MATLAB. (see How to Publish in MATLAB below for more information)
  • Only print values which are asked for in the problem. You can suppress any other output with a ; at the end of the line. Error messages and long pages of extraneous output will automatically earn you a "zero" on the problem.
  • All outputs and graphs must be labeled. (see How to label Matlab output and graphs)
  • Any "paper and pencil" problems may written or typed and printed and included in the rest of the assignment.

How to Publish in MATLAB

You will be expected to use the publish to html option in MATLAB to format your code and output. This feature creates a nicely formatted version of your work, which can be viewed in MATLAB or any web-browser. You should then print the html version of the work as displayed in MATLAB or the browser. Problems which are incorrectly formatted with receive zero credit Do not submit an assignment if you are unsure of the formatting. Email me or see me during office hours if you have any questions.

To format the published file correctly, you must use the correct MATLAB Markup. Lines starting with %% will refer to the main title and subsequent section title. Lines starting with % placed after a line with %% will be printed as the main text for the section, and will be used to answer and state any observations about the problem. More details information about MATLAB's Publishing Markup can be found here.

Example 1 The following code (in an m-file named sample.m):

%% Example problem
%% (a)
% Consider the function f(x) = sin(x)-x. Let x=10^-7 and print out y=f(x) with 15 digits.
%
% How many of these digits are correct???

x = 1e-7;
y = sin(x) - x;
fprintf('y = %.15g\n',y)    % print y with 15 digits

%% (b)
% Plot the function f(x) for x in [0,10^-7].
%
% Why does the plot look like this???

x = linspace(0,1e-7,1000);  % vector of 1000 equidistant points 0,...,1e-7
y = sin(x) - x;             % vector of function values
plot(x,y)                   % plot vector y vs. vector x
xlabel('x')
title('function sin(x)-x')

will produce sample.html, which can then be printed.

Example 2 The following code:

%% Problem title

%% (a) Title of first part
% Description and comments
% and observations
% and so on

format compact              % tells Matlab not to print blank lines between answers
v1 = [-1;2;2]
v2 = [2;-1;2]
innerproduct = dot(v1,v2)   % gives zero, i.e. v1 and v2 are orthogonal

%%  (b) Title of second part
% Description and comments
% and observations
% and so on

x = 0:.1:10;                % use semicolon for stuff you don't want to print!
plot(x,sin(x),x,cos(x))
legend('sin(x)','cos(x)')

%% (c) Title of third part
% Note that Matlab is very picky about the format:
%
% * The % and %% must start in the first column
% * There should be exactly one space after %% and %
% * You can generate a bulleted list like this

will produce the following output.