/* -*-ePiX-*- */ /* cosine.xp -- April 02. 2003 */ #include "epix.h" using namespace ePiX; double cos2(double t) { return 1-(1.0/2.0)*t*t; } double cos4(double t) { return 1-(1.0/2.0)*t*t+(1.0/24.0)*pow(t,4); } const double r1 = sqrt(2); const double r2 = sqrt(6-sqrt(12)); main() { unitlength("1pt"); bounding_box(P(0,-0.25), P(2,1)); picture(320,200); begin(); crop(); h_axis(x_size); v_axis(P(0, 0), P(0, y_max), y_max); // function graphs and labels green(0.5); pen(1); plot(Cos, x_min, x_max, 60); masklabel(P(1, 0.25), "$y=\\cos x$"); plain(); rgb(0.5, 0.5, 0.9); plot(cos2, x_min, x_max, 60); label(P(1, cos2(1)), P(0,0), "$\\displaystyle y = 1-\\frac{1}{2!}x^2$", bl); rgb(0.3, 0, 0.7); plot(cos4, x_min, x_max, 60); label(P(1, cos4(1)), P(0,0), "$\\displaystyle y = 1-\\frac{1}{2!}x^2+\\frac{1}{4!}x^4$", tr); black(); // axis point labels arrow(P(M_PI_2, -0.15), P(M_PI_2, -0.025)); masklabel(P(M_PI_2, -0.15), P(0, -2), "$\\displaystyle\\frac{\\pi}{2}$", b); arrow(P(r1, -0.15), P(r1, -0.025)); label(P(r1, -0.15), P(0, -2), "$\\sqrt{2}$", b); arrow(P(r2, 0.15), P(r2, 0.025)); label(P(r2, 0.15), P(0, 2), "$\\sqrt{6-\\sqrt{12}}$", t); h_axis_labels(x_size, P(0,-4), b); // diagram label label(P(x_max, y_max), P(0,0), "Degree 2 and 4 Taylor polynomials of cosine", bl); end(); }