function piecewisepol(f, a, b, n, k)

	x = linspace(a, b);
	knots = linspace(a, b, n+1);
	
	figure;
	plot(x, f(x));
	hold on;
	
	for knotInd = 1:n
		xInterv = linspace(knots(knotInd), knots(knotInd+1));
		subknots = linspace(knots(knotInd), knots(knotInd+1), k+1);
		y = interpolate(f, subknots, xInterv);
		plot(xInterv, y, 'r');
	end
	
	plot(knots, f(knots), 'r*');
	hold off;
	legend('f', 'p');
end

