% Varialbes
% A scalar
x=5;
% A vector
y1=ones(1,5);% ones(5) will give you a 5 by 5 matrix with all entries to be 1
y2=[1 2 3 4 5]; % or y2=1:5
y3=zeros(1,5);
% A matrix
z1=ones(5);
z2=[1 2 3;3 2 1];
M =[1 2 3; 4 5 6; 7 8 9;];

% Exercise 
A=[1 2 3]; B=[4 5 6];
C = [A B]; % concatenate rows into a single row
D = [A;B]; % concatenate A and B into two rows
E = D(1,2); % get element in row 1, column 2
F = D(2,2:3); % get elements in row 2, columns 2 and 3
G = D(:,3); % get column 3
H = D(1,:); % get row 1
I = H'; % transpose 

% Matrix multiplication
A=[0 2; 1 4]; B=[1 3; 2 6];
A*B
A.*B
A^-1
A.^-1

% Plotting data
x = 0:.2:20;
y1 = sin(x)./sqrt(x+1);
y2 = sin(x/2)./sqrt(x+1);
plot(x, y1, x, y2)

% Can be plotted in the same figure by hold on
plot(x,y1,'b*');
hold on
plot(x,y2,'ro');


% Add a title
title('the plot of two functions')
legend('y1','y2')
xlabel('x')
ylabel('y')

% Exercise: Generate a time scale from 0 to 100. Then produce an array of corresponding values for
% the function y=1-exp(-t./100). Plot the data with labels on the axes and a title.


t=linspace(0,100,10000);
y=1-exp(-t./100);
plot(t,y)
tilte('the plot of the function')
xlabel('time')
ylabel('function value')
















