N = 100;
x = linspace(-pi, pi, N)';  
y = cos(x);   
dy_dx = forward_diff(x, y);
figure;
plot(x, dy_dx, 'b', 'DisplayName', 'Numerical Derivative');
hold on;
plot(x, -sin(x), 'r--', 'DisplayName', 'Analytical -sin(x)');
hold off;

title('Numerical Derivative of cos(x) vs. Analytical Derivative');
xlabel('x');
ylabel('Derivative');
legend show;