% To plot the graph of a function f:R ->R, ie y=f(x) 
%you first define a vector x=(x_1,x_2,...,x_N) 
% whose components are equally spaced 
% points on the x-axis from x=a to x=b, ie
% the j-th component is 
% x_j = a + (j-1)*delta_x where
% we should choose
% delta_x = (b-a)/N.

N=10;
a=0;
b=2*pi;
delta_x=(b-a)/N

x=[a:delta_x:b]

% Next for each component x_j of the vector x we need to
% calculate the y-value, y_j = f(x_j). Let's choose f(x)=cos(x).
% We can do all N components of x at once using: 

y=cos(x)

%Finally we plot the pairs of points (x_j,y_j) for j=1,2,...,N
%and join them with straight lines.

plot(x,y,'bx-')

% Notice that you cxan really see the straight lines joining the
% points when N=10. However if you edit this file to set N=100
% and rerun the code the curve will look much smoother.

% For fun edit this file to plot y=cos(10*x) using N=10.
% You'll get a straight line rather than a cosine curve. Why?
% How can you fix the problem?  
