User:Eml4500.f08.gravy.sms/HW1

Text strings, error messages, input
To enter a text string in MATLAB, use single quotes: s = 'This is a test' This will assign the text string ‘This is a test’ to the variable s.

To display a text string, use the function disp: disp('this message is hereby displayed');

To display an error message, use the function error: error('Sorry, the matrix must be symmetric'); This also will exit the M-file upon execution.

To prompt the user for input data, use the function input: iter = input('Enter the number of iterations: '); This will display ‘Enter the number of iterations’ and pause execution while the user inputs the data which is then data assigned to the variable iter.

Managing M-files
To keep MATLAB active while editing a file in order to avoid losing all variables, use the !-feature by inserting a ! before any system command: >> !ed rotate.m This will let you edit rotate.m using the local editor without exiting MATLAB.

See help dbtype and references given there for more concerning debbugging tools.

The following commands will duplicate system commands without the use of a !:

M-files must be in an accessible directory. Storing personal M-files in a subdirectory named Matlab in one’s home directory should work. For further information see the discussion of MATLABPATH in the User's Guide.

Comparing efficiency of algorithms: flops, tic, toc
There are two measure of algorithm efficiency: floating point operations (flops) performed and the elapsed time (tic and toc).

The MATLAB function flops keeps a running total of the flops performed.

To reset the flops count to 0, use the command fops(0), not flops=0. Do this at the beginning of the code, and then use the command fops at the end to get the fops count of the algorithm: fops (0); x=A\b; fops

The MATLAB functions tic and toc give the elapsed time between the two commands: tic; x=A\b; toc

However, on timesharing machines, elapsed time is not as reliable as flops at determining algorithm efficiency because the rate of execution is dependent on how busy the computer is at the time.

Output format
To control the format of the displayed output, use the following commands:

Once invoked, the chosen format remains in effect until changed.

To suppress most blank lines, use the command format compact. To reverse the format compact command, use format loose. These are independent of the other format commands.