summaryrefslogtreecommitdiff
path: root/graphics/epix/samples/calculus.xp
blob: c5aa0efe0bce166d43d4a6951b6ae78c390a2401 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* -*-ePiX-*- */
#include "epix.h"
using namespace ePiX;

double MAX(2*M_PI);
double f(double t)
{
  return t*Sin(t);
}

int main()
{
  picture(P(-MAX,-MAX), P(MAX,MAX), "240x240pt");

  begin();

  // Coordinate axes and labels
  pen(Black(0.3));
  grid(8,8);

  font_size("scriptsize");
  // trigonometric axis labels
  bottom_axis(4, P(0,-4)).trig().draw_labels();
  left_axis(4, P(-4,0)).trig().draw_labels();

  legend L;
  L.item_border(0).border(Red(), 0.4);

  bold(Black());
  plot(f, xmin(), xmax(), 90);
  L.path_item("$y=x\\sin x$");

  pen(Green());
  plot(Deriv(f), xmin(), xmax(), 90);
  L.path_item("$y=\\frac{d}{dx}(x\\sin x)$");

  pen(Blue());
  plot(Integral(f, 0), xmin(), xmax(), 90); // definite integral from 0
  L.path_item("$y=\\int_0^x t\\sin t\\,dt$");

  L.draw(P(0,2*M_PI), P(2,-2), br);
  end();
}