MATLAB was originally designed to act like a very sophisticated scientific calculator that could aid scientists and engineers in solving the complicated types of problems they frequently encounter in practice. Even in its seventh major upgrade, MATLAB still retains this "calculator" flavor. One way to use MATLAB is to simply type in an expression and press return to force immediate execution of your command. For example, if we type in our favorite rational fraction approximation to pi:
>> 355/113
MATLAB responds with: ans = 3.1416
Notice that unlike what we are used to in C++, MATLAB does not have an integer format - all values are considered floating point, even if we do not type in the decimal point. If we prefer to see the absolute error of this approximation, we could invoke the built in constant pi, thus:
>> pi - 355/113
MATLAB responds with: ans = -2.6676 e-07
This "calculator" mode is augmented with sophisticated matrix manipulation, math functions, programming, and 2 and 3 dimensional graphing and visualization of data. The best way to get involved with MATLAB is simply to begin using it. When you invoke MATLAB, you have access to demo programs, various forms of help and on-line documentation, and tutorials. We have found that the best on-line tutorial available is the one provided by The MATHWORKS Inc. (the developers of MATLAB), called "Getting Started with MATLAB". This tutorial is available from within MATLAB by typing the command "helpdesk". You will notice while going through this tutorial that in order to fully appreciate the power of programming in this very useful language you will need to obtain a background in the handling and use of vectors and matrices. We strongly advise that you take an elective course in matrices, such as MATH410. This lab is much less ambitious. We will guide you through a select few of the MATLAB statements to enable you to interactively read the data from the data files, and produce the plot. This will also aid you in developing the plot required for your current homework programming exercise.
For the purposes of this lab we assume that you have transferred the two data files sine.data and dart.data into the temp directory on the C: drive, and that you have used the horizontal tab symbol '\t' to delimit the two columns of data. In the interactive program that follows, each line is followed by a semicolon ;. This optionally suppresses the computer response, and you may leave it out if you wish to see how the computer responds to each command line. Specifying a variable (such as sine, xsine, and ysine below) automatically creates it, and the variable automatically adapts its data structure to match the data being assigned to it. The % symbol indicates the start of a comment until the end of the line (similar to the C++ //).
sine = dlmread('c:\temp\sine.data', '\t'); % delimited read
xsine = sine(:, 1); % extracting the first column of data
ysine = sine(:, 2); % extracting the second column of data
plot(xsine, ysine)
grid on
hold on
axis([0, pi, 0, 1]) % specifying the limits on the x and y axes

We continue with the overlay plot of the random darts:
darts = dlmread('c:\temp\dart.data', '\t');
xdart = darts(:, 1);
ydart = darts(:, 2);
help plot % allows you to evaluate the various plotting options
plot(xdart, ydart, 'rd') % we chose red diamonds with no line
Finally, we complete the plot with suitable labels and titles:
title('Darts at O''Hooley''s')
xlabel('angle (radians)')
ylabel('sine (angle)')
gtext('Estimating area by counting darts under curve')
% move mouse to select the position of the message