%Christopher Lum
%lum@u.washington.edu
%
%Matlab Tutorial (beginner)

%Version History:   -09/25/10: Updated

clear           %clears all variables from the Workspace
clc             %clears the Command Window
close all       %closes all figures (such as plots)

%-----------------------USING MATLAB---------------------------------------
%Enter in the x and y components of the vector.  Remember that the ";" will
%suppress the output to the Command Window.
x = 2.5;
y = 2;

%Calculate something using previously defined variables.
z = x + y;

%Create a 2D vector
v = [x;y];
p = [12 -3];

%Create a 2D matrix
A = [1 3; 3 4; p];

%Perform some operations
q = A*v

%--------------------2D PLOTTING WITH MATLAB-------------------------------
%Function 1:    f1(x) = 3*x + 4
x = [-1 0 1 2];         %desired x values of function
y = 3*x + 4;            %function evaluated at x

figure                              %start a new figure
plot(x,y)                           %plot function
xlabel('x')                         %add x label to figure
ylabel('y = f(x)')                  %add y label to figure
grid on                             %turn on the grid on figure
title('Plot of function f_1(x)')    %add title to figure
legend('f_1(x)')                    %add legend to figure
axis([-2 4 -2 12])                  %force axis to be drawn in specified range

%Function 2:    f2(t) = g(t)*h(t)
%
%   where       g(t) = 3*t^2
%               h(t) = sin(4*t + 4)
t = [0:.01:5];

gt = 3*t.^2;
ht = sin(4*t + 4);

f2 = gt.*ht;

figure
plot(t,f2,'rx')

