function [a,w0,fval,supvecs,margvecs] = trainsvm(x,y,C,kernalfunc,varargin)

  if nargin<4
      kernalfunc = 'polyK';
  end
  
  % Evaluate the kernel function on all pairs of input vectors
  K = feval(kernalfunc,x,x,varargin{:});
  
  %% Insert code to solve the quadratic programing problem:
  [a,fval] = quadprog(.....);

  % Find the support vectors and the vectors the are exactly on the margin
  eps = 0.001*max(a); % Allow for some inacuracy
  supvecs = find(a>=eps); % Support vectors
  margvecs = find(a>=eps & a<=C-eps); % Only those on the margin
  
  %% Insert code to recover w0:
  w0 = median(......);
  
  
