By Topic By Date Reply Class Web

Previous Next

using diaries for 352 homework





A student sent mail asking how Homework 1 should be turned in.
I'd like you to turn in the input and output from doing the matlab problems
(printed out -- please don't email the files).

One way to do this is to make an m-file script that gives lists all the
commands needed to do the problems.  You can modify this script and rerun it
as many times as needed to get everything right.   (Or you might want to
write a different script for each problem so you can work on them
separately.)

Then you can run the script(s) with "echo on" and "diary on" in order to
capture all the input and output into a file.

For example, suppose that for a hypothetical homework #0 the commands
are stored in hw0.m as follows:

------------------------------------------------------------------------

A = diag(1:3)
x = ones(3,1)
A*x

------------------------------------------------------------------------

Then in matlab you could type

>> echo on
>> diary 'hw0.sol' on
>> hw0
>> diary 'hw0.sol' off
>> echo off


The result would be a file hw0.sol containing:

------------------------------------------------------------------------
>> hw0

A = diag(1:3)

A =

     1     0     0
     0     2     0
     0     0     3

x = ones(3,1)

x =

     1
     1
     1

A*x

ans =

     1
     2
     3

>> diary 'hw0.sol' off
------------------------------------------------------------------------

You can edit this file if you want to add some headers for the individual
problems, for example. (But please don't edit the matlab output to make it
look "right" if your commands aren't working properly!)