Difference between revisions of "User:Tigerbw/Asymptote/graphing"
< User:Tigerbw | Asymptote
(→Source Code) |
(→Graphing) |
||
(2 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
{{User:Tigerbw/Templates/header}} | {{User:Tigerbw/Templates/header}} | ||
====Graphing==== | ====Graphing==== | ||
− | So basically, I was | + | So basically, I was sigma one day, and I wanted to do some stuff so I went to Desmos. I got sigma again, so I thought to make Desmos in asymptote. This is what I got |
<asy> | <asy> | ||
Line 28: | Line 28: | ||
real f(real x){ // equation to graph | real f(real x){ // equation to graph | ||
− | if (x!= | + | if (x!=0) { // check for impossible case |
− | return | + | return 1/x; |
} | } | ||
else{ | else{ | ||
Line 113: | Line 113: | ||
grid(); | grid(); | ||
dotgraph(); | dotgraph(); | ||
− | </syntaxhighlight | + | </syntaxhighlight> |
Latest revision as of 00:27, 7 August 2024
Graphing
So basically, I was sigma one day, and I wanted to do some stuff so I went to Desmos. I got sigma again, so I thought to make Desmos in asymptote. This is what I got
Source Code
1 /**
2 * Graphing Remastered
3 *
4 * Made by tigerbw
5 */
6
7 real resolution, x_left, x_right, g_x_left, g_x_right, y_down, y_up;
8 resolution = 0.001;
9 x_left = -8;
10 x_right = 8;
11 y_down = -8;
12 y_up = 8;
13 g_x_left = -8;
14 g_x_right = 8;
15 pen gray_pen = gray(.7);
16 pen graph_pen = 1+blue;
17 void grid(){
18 real[] arrx, arry;
19 for (real i = x_left+1; i < x_right; i+=1){
20 draw((i, y_down)--(i, y_up), gray_pen);
21 }
22 for (real i = y_down+1; i < y_up; i+=1){
23 draw((x_left, i)--(x_right, i), gray_pen);
24 }
25 draw((x_left, 0)--(x_right, 0),Arrows);
26 draw((0,y_down)--(0, y_up),Arrows);
27
28 }
29
30 real f(real x){ // equation to graph
31 if (x!=1) { // check for impossible case
32 return x^2/((x-1));
33 }
34 else{
35 return y_up+1;
36 }
37 }
38
39 void dotgraph(){
40 bool prev = false;
41 for (real i = g_x_left; i<=g_x_right; i+= resolution){
42 if (f(i)<y_up && f(i) > y_down){
43 if (prev == true){
44 draw((i, f(i))--(i-resolution, f(i-resolution)), graph_pen);
45 }
46 prev = true;
47 }
48 else{
49 prev = false;
50 }
51 }
52 }
53
54 grid();
55 dotgraph();