%% HOW DO I DO THAT IN MATLAB SERIES?
% In this series, I am answering questions that students have asked
% me about MATLAB.  

%% TOPIC
% How do I conduct matrix operations in Matlab
%% SUMMARY
% Language : Matlab 2008a; 
% Authors : Sri Harsha Garapati, Daniel Miller, Autar Kaw; 
% Mfile available at
% http://numericalmethods.eng.usf.edu/blog/matrix_ops_ex2_blog.m; 
% Last Revised : January 17, 2012; 
% Abstract: This program shows you how to perform matrix operations 
%       i.e. addition, subtraction, multiplication, element to element
%       multiplication
clc
clear all

%% INTRODUCTION

disp('ABSTRACT')
disp('   This program shows you how to perform matrix operations ')

disp(' ')
disp('AUTHOR')
disp('   Sri Harsha Garapati, Daniel Miller and')
disp('Autar K Kaw of http://autarkaw.wordpress.com')
disp(' ')
disp('MFILE SOURCE')
disp('   http://numericalmethods.eng.usf.edu/blog/matrix_ops_ex2_blog.m')
disp(' ')
disp('LAST REVISED')
disp('   January 17, 2012')
disp(' ')

%% INPUTS

% Matrix, a
a=[1 2 6; 2 65 1; 4 2 1];
%Matix, b
b=[2 3 4; 2 1 45; 9 3 6];
%% DISPLAYING INPUTS

disp('INPUTS')
disp(' Matrix,a')
%printing matrix a
disp(a)
disp('Matrix, b')
%printing matrix b
disp(b)
%% THE CODE

% a) adding two matrices
% [a]+[b]=[c]
c=a+b;

% b) subtracting two matrices
% [a]-[b]=[d]
d=a-b;

% c) muliplying two matrices
% [a]*[b]=[e]
e=a*b;

% d) two times the scalar product of matrix a and b is matrix f
f=2.*[a].*([b]);
%% DISPLAYING OUTPUTS
disp('  ')
disp('OUTPUTS')
disp(' a) Addition of two matrices a and b gives the resulting matrix:')
disp(c)
disp(' b) Subtraction of two matrices a and b gives the resulting matrix:')
disp(d)
disp(' c) Multiplication of two matrices a and b gives the resulting matrix:')
disp(e)
disp(' c) Two times the scalar product of two matrices a and b gives the resulting matrix:')
disp(f)

