%%% Note earlier versions of Matlab (e.g. 7.1) have a different syntax

p = [0 0 1 1;0 1 0 1];
t=[0 1 1 0]
net=patternnet(3)   % modify the number of hidden units for part  d)

net.trainFcn='traingd';  % comment these two lines out for part  c)
net.trainParam.lr=1;      % modify this number for part b) 

%net.trainFcn='trainscg';    % uncomment this line for part c)

net.trainParam.epochs=1000;    % this tells how many epochs to do before timing out (if you haven't already converged) 

net.trainParam.goal = 0.005;    % this tells how much mean square error we're willing to tolerate
net.divideFcn='';  %%% We don't want to divide training set in this simple case
[net tr]=train(net,p,t);  %% train the network

%%%% the next line checks the final output on all the patterns  
%%%%  note we want a to be similar to t at the end of training
a = sim(net,p)

