Giải: Chúng ta thực hiện trên trình biên soạn của Matlab như sau:
N = 50;
x = 0:2*pi/N:4*pi;
f = @sin;
g = @cos;
y1 = f(x);
y2 = g(x);
e1 = std(y1)*ones(size(x));
e2 = std(y2)*ones(size(x));
plot(x,y1, '--r','LineWidth',3);
errorbar(x,y1,e1);
xlabel('x');
ylabel('sin(x), cos(x)');
grid on
hold on
plot(x,y2, '-b','LineWidth',3);
axis([0,4*pi,-2,2]);
legend('sin(x)','cos(x)','FontName','Times New Roman','FontSize',12);