60 |
jpm |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
* This work is hereby released into the Public Domain.
|
|
|
4 |
* To view a copy of the public domain dedication,
|
|
|
5 |
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
|
|
6 |
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
|
|
7 |
*
|
|
|
8 |
*/
|
|
|
9 |
|
|
|
10 |
require_once "../../MathPlot.class.php";
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
$graph = new Graph(300, 300);
|
|
|
14 |
|
|
|
15 |
$plot = new MathPlot(-3, 3, 3, -3);
|
|
|
16 |
$plot->setInterval(0.2);
|
|
|
17 |
$plot->setPadding(NULL, NULL, NULL, 20);
|
|
|
18 |
|
|
|
19 |
$function = new MathFunction('cos');
|
|
|
20 |
$function->setColor(new DarkGreen);
|
|
|
21 |
$function->mark->setType(Mark::SQUARE);
|
|
|
22 |
$function->mark->setSize(3);
|
|
|
23 |
$plot->add($function, "f(x) = cos(x)", Legend::MARK);
|
|
|
24 |
|
|
|
25 |
$function = new MathFunction('exp');
|
|
|
26 |
$function->setColor(new DarkRed);
|
|
|
27 |
$function->mark->setType(Mark::SQUARE);
|
|
|
28 |
$function->mark->setSize(3);
|
|
|
29 |
$function->mark->setFill(new DarkBlue);
|
|
|
30 |
$plot->add($function, "f(x) = exp(x)", Legend::MARK);
|
|
|
31 |
|
|
|
32 |
function x2($x) {
|
|
|
33 |
return - $x * $x + 0.5;
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
$function = new MathFunction('x2');
|
|
|
37 |
$function->setColor(new DarkBlue);
|
|
|
38 |
$plot->add($function, "f(x) = - x * x + 0.5");
|
|
|
39 |
|
|
|
40 |
$plot->legend->setPosition(0.9, 0.8);
|
|
|
41 |
$plot->legend->setPadding(3, 3, 3, 3, 3);
|
|
|
42 |
|
|
|
43 |
$graph->add($plot);
|
|
|
44 |
$graph->draw();
|
|
|
45 |
?>
|