MATLAB: When I put legend for 3 functions it only shows 1 on the graph

#legend#graphlegend

Hi, below is my script:
x=linspace(0,2*pi,100);
y1=1-x.^2/factorial(2);
y2=y1+x.^4/factorial(4);
y3=cos(x);
plot(x,y1,'k:')
legend('2 terms approx')
hold on
plot(x,y2,'k--')
legend('3 terms approx')
hold on
plot(x,y3,'r')
legend('cos(x)')
xlabel('x')
ylabel('y')
Thanks!

Best Answer

Try this:
legend('2 terms approx','3 terms approx','cos(x)')