%
% A02.m
%
% Calculate the period of a pendulum
%
% Demonstrates:  how to input data into the program and output nicely
%                   formatted messages to the command window
%
% INPUT:    User is prompted to enter the length of a simiple pendulum
% OUTPUT:   The period is calculated and displayed in the command window 
%
% Matlab-Monkey.com
% 12/30/2014

clc         % clear command window
clear       % clear all variables
close all   % close all graphics windows

g = 9.8;    % define acceleration of gravity in MKS units

% prompt user to enter the length of a pendulum
L = input('Enter length of pendulum (in meters):  ');

% calculate the period
P = 2*pi*sqrt(L/g);

% the first fprintf statement prints a blank line to space things out.
% the second fprintf statement prints the period of the pendulum in command 
% window and specifies that 3 sig figs should be displayed.
fprintf('\n')
fprintf('Period = %.3g seconds\n',P)
