-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc.htm
More file actions
783 lines (674 loc) · 25 KB
/
doc.htm
File metadata and controls
783 lines (674 loc) · 25 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="main.css">
<title>Function grapher manual</title>
</head>
<body>
<p><a href="doc-de.htm">De</a> | <a href="home.htm">Home</a>
</p>
<h1>Function grapher manual</h1>
<h2 id="toc">Table of contents</h2>
<ol>
<li><b><a href="#Constants">Constants</a></b>
<li><b><a href="#Functions">Functions</a></b>
<ol class="modest">
<li><a href="#Basic">Basic functions</a>
<li><a href="#Trigonometric">Trigonometric functions</a>
<li><a href="#Hyperbolic">Hyperbolic functions</a>
<li><a href="#Wave">Wave forms</a>
<li><a href="#Analysis">Analysis</a>
<li><a href="#Enhancement">Enhancement functions</a>
<li><a href="#Gamma">Gamma and related</a>
<li><a href="#Combinatorical">Combinatorical functions</a>
<li><a href="#Elliptic-integrals">Elliptic integrals and related</a>
<li><a href="#Antiderivatives">Antiderivatives</a>
<li><a href="#Bessel">Bessel and related</a>
<li><a href="#Hypergeometric">Hypergeometric functions</a>
<li><a href="#Zeta">Zeta and related</a>
<li><a href="#Polynomial">Polynomial functions</a>
<li><a href="#Fourier">Fourier analysis</a>
<li><a href="#Functional-analysis">Functional analysis</a>
<li><a href="#Other">Other functions</a>
<li><a href="#Number-theoretic">Number theoretic functions</a>
<li><a href="#Statistical">Statistical functions</a>
</ol>
<li><b><a href="#CFunctions">Complex functions</a></b>
<ol class="modest">
<li><a href="#CBasic">Basic functions</a>
<li><a href="#CTrigonometric">Trigonometric functions</a>
<li><a href="#CHyperbolic">Hyperbolic functions</a>
<li><a href="#CAnalysis">Complex analysis</a>
<li><a href="#Gamma">Gamma and related</a>
<li><a href="#CAntiderivatives">Antiderivatives</a>
<li><a href="#CZeta">Zeta and related</a>
<li><a href="#COther">Other</a>
</ol>
<li><b><a href="#Operators">Operators</a></b>
<li><b><a href="#Syntax">Syntax and semantics</a></b>
<li><b><a href="#Graphers">The graphers in detail</a></b>
<li><b><a href="#Examples">Examples</a></b>
<li><b><a href="#Advanced">Advanced</a></b>
</ol>
<h2 id="Constants">
Constants</h2>
<pre>
e......Euler's number
pi.....Circle constant
gc.....Euler-Mascheroni constant
deg....pi/180
</pre>
<h2 id="Functions">Functions</h2>
<pre>
<b id="Basic">Basic functions</b>
abs(x)........absolute value
sgn(x)........signum function
sqrt(x).......square root
root(n,x).....nth root
floor(x)......rounds x down
ceil(x).......rounds x up
rd(x).........rounded value
frac(x).......fractional part
max(a,b)......maximum
min(a,b)......minimum
mod(x,m)......modulo funktion
H(x)..........unit step function
exp(x)........natural exponential function
ln(x).........natural logarithm
lg(x).........decadic logarithm
ld(x).........logarithm to base two
log(x,b)......logarithm to base b
<b id="Trigonometric">Trigonometric functions</b>
sin(x)........sine
cos(x)........cosine
tan(x)........tangent
cot(x)........cotangent
sec(x)........secant
csc(x)........cosecant
asin(x).......arc sine
acos(x).......arc cosine
atan(x).......arc tangent
acot(x).......arc cotangent
asec(x).......arc secant
acsc(x).......arc cosecant
gd(x).........Gudermann function
hypot(x,y)....length of the coordinate vector (x,y)
angle(x,y)....angle of the coordinate vector (x,y)
<b id="Hyperbolic">Hyperbolic functions</b>
sinh(x).......sine hyperbolicus
cosh(x).......cosine hyperbolicus
tanh(x).......tangent hyperbolicus
coth(x).......cotangent hyperbolicus
sech(x).......secant hyperbolicus
csch(x).......cosecant hyperbolicus
asinh(x)......area sine hyperbolicus
acosh(x)......area cosine hyperbolicus
atanh(x)......area tangent hyperbolicus
acoth(x)......area cotangent hyperbolicus
asech(x)......area secant hyperbolicus
acsch(x)......area cosecant hyperbolicus
<b id="Wave">Wave forms</b>
twave(x,p)....triangle wave, p-periodic
ptwave(x,p)...positive triangle wave, p-periodic
sqwave(x,p)...square wave, p-periodic
psqwave(x,p)..positive square wave, p-periodic
stwave(x,p)...sawtooth wave, p-periodic
pstwave(x,p)..positive sawtooth wave, p-periodic
<b id="Analysis">Analysis</b>
diff(f,x).....derivative of f at x
diff(f,x,2)...second derivative of f at x
diff(f,x,n)...nth derivative of f at x
int(f,0,x)....integral(from 0 to x) f(t) dt
int(f,0,x,n)..integration with n steps
pow(f,n,x)....composition of function f with itself
sum(f,a,b)....sum(k=a to b) f(k)
prod(f,a,b)...product(k=a to b) f(k)
rand(a,b).....random number in the interval [a,b)
inv(f,x)......inverse function f^(-1)(x)
inv(f,x,a,b)..f^(-1)(x) for f defined on [a,b]
<b id="Enhancement">Enhancement functions</b>
[a1,...,an]...constructs a list from the values a1,...,an
get(a,i)......element number i of the list a
size(a).......number of elements in the list a
cat(a,b)......concatenates the lists a and b
range(a,b)....constructs the list [a,a+1,a+2,...,b]
range(a,b,d)..constructs the list [a,a+d,a+2d,...,b]
next(a).......cyclically picks an element from the list a
rand(a).......randomly picks an element from the list a
sum(a)........sum of all elements in the list a
prod(a).......product of all elements in the list a
max(a)........maximum of all elements in the list a
min(a)........minimum of all elements in the list a
rev(a)........reversed list
ipp(a)........interpolation polynomial, a=[[x0,y0],...,[xn,yn]]
fn(a).........piecewise linear interpolation
fn(x0,d,a)....piecewise linear interpolation, equidistant nodes
map(f,a)......applys the function f to all elements in a
filter(f,a)...filters elementes from the list a
reduce(f,a)...reduces a with f(x,y)
compose(a)....composition of all functions in the list a
count(f,a)....counts how often f(x) for x in a is true
forall(f,a)...f(x) is true for all x in a
exists(f,a)...f(x) is true for any x in a
table(f,a)....lookup table of f for the list a
apply(f,x)....application of f to x
if(c,a,b).....if c then a else b
not(a)........logical negation
clamp(x,a,b)..min(max(x,a),b)
sma(f,x,n,h)..central simple moving average
<b id="Gamma">Gamma and related</b>
fac(x)........factorial
gamma(x)......gamma function
digamma(x)....digamma function
pgamma(n,x)...polygamma function
B(a,b)........beta function
gamma(s,x)....lower incomplete gamma function
Gamma(s,x)....upper incomplete gamma function
B(x,a,b)......incomplete beta function B[x](a,b)
I(x,a,b)......B(x,a,b)/B(a,b)
G(x)..........Barnes G-function
hyperK(x).....K-function
<b id="Combinatorical">Combinatorical functions</b>
bc(n,k).......binomial coefficient
ff(n,k).......falling factorial
rf(n,k).......raising factorial
s1(n,k).......Stirling number of the first kind
s2(n,k).......Stirling number of the second kind
<b id="Elliptic-integrals">Elliptic integrals and related</b>
K(m)..........complete elliptic integral K(m=k^2)
E(m)..........complete elliptic integral E(m=k^2)
F(phi,m)......incomplete elliptic integral F(phi,m=k^2)
E(phi,m)......incomplete elliptic integral E(phi,m=k^2)
Pi(phi,n,m)...incomplete elliptic integral Pi(phi,n,m=k^2)
RF(x,y,z).....Carlson symmetric form RF(x,y,z)
RJ(x,y,z,p)...Carlson symmetric form RJ(x,y,z,p)
RC(x,y).......shorthand for RF(x,y,y)
RD(x,y,z).....shorthand for RJ(x,y,z,z)
agm(a,b)......arithmetic-geometric mean
magm(a,b).....modified arithmetic-geometric mean
<b id="Antiderivatives">Antiderivatives</b>
Ei(x).........exponential integral
En(n,x).......exponential integral E[n](x)
li(x).........integral logarithm
Li(x).........integral logarithm with offset li(2)
Si(x).........sine integral
Ci(x).........cosine integral
<b id="Bessel">Bessel and related</b>
BJ(a,x).......Bessel function J[a](x)
BY(a,x).......Bessel function Y[a](x)
Bj(a,x).......spherical Bessel function j[a](x)
By(a,x).......spherical Bessel function y[a](x)
BI(a,x).......modified Bessel function I[a](x)
BK(a,x).......modified Bessel function K[a](x)
Ai(x).........Airy function Ai(x)
Bi(x).........Airy function Bi(x)
<b id="Hypergeometric">Hypergeometric functions</b>
F([a1,...,am],[b1,...,bn],x)
..............hypergeometric function
M(a,b,x)......confluent hypergeometric function M(a,b,x)
U(a,b,x)......confluent hypergeometric function U(a,b,x)
<b id="Zeta">Zeta and related</b>
zeta(s).......zeta function
zeta(s,a).....Hurzwitz zeta function
Phi(x,s,a)....Lerch transcendent
Li(s,x).......polylogarithm Li[s](x)
B(k)..........Bernoulli number, B(1)=+1/2
Bm(k).........Bernoulli number, Bm(1)=-1/2
<b id="Polynomial">Polynomial functions</b>
PP(n,a,x).....Legendre polynomial P[n,a](x)
PL(n,a,x).....Laguerre polynomial L[n,a](x)
PH(n,x).......Hermite polynomial H[n](x)
PT(n,x).......Chebyshev polynomial T[n](x)
PU(n,x).......Chebyshev polynomial U[n](x)
<b id="Fourier">Fourier analysis</b>
fa(f,i,j).....Fourier coefficients a[i] upto a[j]
fb(f,i,j).....Fourier-coefficients b[i] upto b[j]
fs(x,a0,a,b)..Fourier series, a=[a1,a2,...], b=[b1,b2,...]
fs(x,a0,a)....amplitude-phase form(cos), a=[[A1,phi1],[A2,phi2],...]
Fs(f,x).......sine transform, x in Hz
Fc(f,x).......cosine transform, x in Hz
comb(x,a,p)...Dirac comb of sharpness a und period p
<b id="Functional-analysis">Functional analysis</b>
sinc(x).......cardinal sine: sin(pi*x)/(pi*x)
delta(x,a)....Dirac delta function
L(f,x)........Laplace transform
E(a,b,x)......Mittag Leffler function
D(f,x,r)......fractional derivative (D^r)(f)(x)
J(f,a,x,r)....Riemann-Liouville integral (J[a]^r)(f)(x)
J2(f,a,x,r)...Riemann-Liouville integral, alternative algorithm
<b id="Other">Other functions</b>
W(x)..........Lambert W-function, upper branch
Wm1(x)........Lambert W-function, lower branch
<b id="Number-theoretic">Number theoretic functions</b>
pm(x,n,m).....modular power
gcd(a,b)......greatest common divisor
lcm(a,b)......least common multiple
isprime(n)....prime number test
primes(m,n)...the list of prime numbers between m and n
factor(n).....prime number factorization
pcf(n)........prime number counting function pi(n)
phi(n)........Euler's totient function
lambda(n).....Carmichael function
sigma(n,k)....divisor function sigma[k](n)
<b id="Statistical">Statistical functions</b>
erf(x)........error function
norm(x).......cumulative standard normal distribution
mean(a).......arithmetic mean of the elements of a
sd(a).........standard deviation of the elements of a
cdf(a,x)......CDF for the random numbers in a
pmf(a,x)......PMF, a is a list of integer numbers
pmfB(n,p,k)...binomial distribution, PMF
cdfB(n,p,k)...binomial distribution, CDF
pmfG(p,k).....geometric distribution, PMF
cdfG(p,k).....geometric distribution, CDF
pmfH(N,K,n,k)...hypergeometric distribution, PMF
cdfH(N,K,n,k)...hypergeometric distribution, CDF
pmfP(lambda,k)...Poisson distribution, PMF
cdfP(lambda,k)...Poisson distribution, CDF
pmfLog(p,k)...logarithmic distribution, PMF
cdfLog(p,k)...logarithmic distribution, CDF
pdfN(mu,sigma,x)...normal distribution, PDF
cdfN(mu,sigma,x)...normal distribution, CDF
pdfLogN(mu,sigma,x)...log-normal distribution, PDF
cdfLogN(mu,sigma,x)...log-normal distribution, CDF
pdfExp(lambda,x)...exponential distribution, PDF, E=1/lambda
cdfExp(lambda,x)...exponential distribution, CDF, E=1/lambda
pdfst(n,x)....student's t-distribution, PDF
cdfst(n,x)....student's t-distribution, CDF
pdfF(m,n,x)...Fisher distribution, PDF
cdfF(m,n,x)...Fisher distribution, CDF
pdfW(a,b,x)...Weibull distribution, PDF, E=b*gamma(1+1/a)
cdfW(a,b,x)...Weibull distribution, CDF, E=b*gamma(1+1/a)
pdfGamma(b,p,x)...Gamma distribution, PDF, E=p/b
cdfGamma(b,p,x)...Gamma distribution, CDF, E=p/b
pdfBeta(p,q,x)...Beta distribution, PDF
cdfBeta(p,q,x)...Beta distribution, CDF
</pre>
<h2 id="CFunctions">Complex functions</h2>
<pre>
<b id="CBasic">Basic functions</b>
re(z).........real part
im(z).........imaginary part
conj(z).......conjugation
arg(z)........phase
abs(z)........absolute value
sgn(z)........signum function
sqrt(z).......square root
root(n,z).....nth root
exp(z)........natural exponential function
ln(z).........natural logarithm
lg(z).........decadic logarithm
log(z,b)......logarithm to base b
<b id="CTrigonometric">Trigonometric functions</b>
sin(z)........sine
cos(z)........cosine
tan(z)........tangent
cot(z)........cotangent
asin(z).......arc sine
acos(z).......arc cosine
atan(z).......arc tangent
acot(z).......arc cotangent
<b id="CHyperbolic">Hyperbolic functions</b>
sinh(z).......sine hyperbolicus
cosh(z).......cosine hyperbolicus
tanh(z).......tangent hyperbolicus
coth(z).......cotangent hyperbolicus
asinh(z)......area sine hyperbolicus
acosh(z)......area cosine hyperbolicus
atanh(z)......area tangent hyperbolicus
acoth(z)......area cotangent hyperbolicus
<b id="CAnalysis">Complex analysis</b>
diff(f,z).....complex derivative
diff(f,z,n)...nth complex derivative
int(f,a,b)....integral(from a to b) f(t) dt
cint(f,g).....contour integral(from g(0) to g(1)) f(z) dz
vint(f,a).....contour integral(from get(a,1) to get(a,n)) f(z) dz
<b id="Gamma">Gamma and related</b>
fac(z)........factorial
gamma(z)......gamma function
digamma(z)....digamma function
gamma(s,z)....lower incomplete gamma function
Gamma(s,z)....upper incomplete gamma function
<b id="CElliptic-integrals">Elliptic integrals and related</b>
K(m)..........complete elliptic integral K(m=k^2)
E(m)..........complete elliptic integral E(m=k^2)
<b id="CAntiderivatives">Antiderivatives</b>
erf(z)........error function
Ei(z).........exponential integral
En(n,z).......exponential integral E[n](z)
<b id="CZeta">Zeta and related</b>
zeta(s).......zeta function
zeta(s,a).....Hurzwitz zeta function
Phi(x,s,a)....Lerch transcendent
B(k)..........Bernoulli number
<b id="COther">Other</b>
theta1(z,q)...theta function theta1(z,q)
theta2(z,q)...theta function theta2(z,q)
theta3(z,q)...theta function theta3(z,q)
theta4(z,q)...theta function theta4(z,q)
sn(z,k).......sinus amplitudinis
cn(z,k).......cosinus amplitudinis
dn(z,k).......delta amplitudinis
</pre>
<h2 id="Operators">
Operators</h2>
<pre>
01 f\x.....f applied to x
02 a^b.....a to the power of b
03 +a......plus a
03 -a......minus a
04 a*b.....a times b
04 a/b.....a divided by b
04 a%b.....a modulo b
05 a+b.....a plus b
05 a-b.....a minus b
06 a:b.....[a, a+1, a+2, ..., b]
06 a:b:d...[a, a+d, a+2d, ..., b]
07 a<b.....if a is less than b then 1 else 0
07 a>b.....if a is greater than b then 1 else 0
07 a<=b....if a is less than or equal to b then 1 else 0
07 a>=b....if a is greater than or equal to b then 1 else 0
08 a=b.....if abs(a-b)<epsilon then 1 else 0
08 a!=b....if abs(a-b)>epsilon then 1 else 0
09 a&b.....a and b
10 a|b.....a or b
</pre>
<h2 id="Syntax">
Syntax and semantics</h2>
<pre>
Care should be taken of the following:
* The decimal mark is a point.
(the sign which separates fractional part from integer part)
* x to the power of 2 is written x^2.
* In place of x^-1 you have to write x^(-1).
* The power operator is left-associative.
That means a^b^c = (a^b)^c.
* x/a/b means (x/a)/b.
* In place of 2*x you can also write 2x.
* In place of (x+2)*(x-2) you can also write (x+2)(x-2).
* But in place of x(x-1) you have to write x*(x-1).
* Omitting the multiplication sign in a*x and x*x is also
not allowed.
If a hash sign (#) is written at the beginning of the input line,
then the following function is defined, but not graphed.
For example the follwing input is possible:
f(x) = # sin(x)
g(x) = f(2x)
The notation {x| term of x} is used for the definition of anonymous
functions. For example, the function which maps x to 2x is written
{x|2x}, or alternatively {t|2t} or {u|2u}. This function can be
applied to the variable x like a named function: {t|2t}(x). This is
advantageous in certain cases. For example, the function
f(x) = 1+(x-2)+(x-2)^2/2+(x-2)^3/6
can also be written as
f(x) = {x|1+x+x^2/2+x^3/6}(x-2).
The derivative of x^2 can be stated as
f(x) = diff({t|t^2},x).
An alternative formulation is
f(x) = x^2,
g(x) = diff(f,x).
To draw f(x) = integral(from 0 to x) 2t dt,
write f(x) = int({t|2t},0,x).
The operator ":=" is used to assign a value to a variable.
Instead of
f(x,y) = sin(sqrt(x^2+y^2))/sqrt(x^2+y^2)
you may also write
f(x,y) = r:=sqrt(x^2+y^2), sin(r)/r.
It is also possible to draw a bunch of functions at the same time.
Examples:
f(x) = next([x,x^2,1/x])
f(x) = next([-2,-1,1,2])*sin(x)
f(x) = next(-4:4)*sin(x)
If the graphs of the functions are not continuous,
to make them continous increase the number of points.
If a statement has to be evaluated only once, the statement has to
appear behind a semicolon. For example, there is a difference between
f(x) = r:=rand(0,1), x+r
and
f(x) = x+r; r:=rand(0,1).
</pre>
<h2 id="Graphers">
The graphers in detail</h2>
<pre>
<b>Grapher for real functions</b>
px: viewpoint, x-coordinate
py: viewpoint, y-coordinate
wx: width of the view
wy: height of the view
The x-interval of the view is
[px-wx, px+wx]
and the y-interval is
[py-wy, py+wy].
n: number of points in the interval
[px, px+wx]
a: parameter
d: distance (a:=a-d, a:=a+d)
b: parameter
d: distance (b:=b-d, b:=b+d)
<b>Grapher for implicit functions</b>
To draw two functions simultaneously, simply connect them with
a logical OR. An example is
x*y=1 | y=x.
Replacement of OR (|) with AND (&) results in an equation system.
It is also possible to draw inequalities, for example
abs(x)+abs(y)<1.
<b>Grapher for solutions of differential equations</b>
Write y1 instead of y' and y2 instead of y'' and so on.
<b>Grapher for systems of two differential equations</b>
We want to study the damped oscillator wich is defined by the
equation y''+0.2y'+sin(y)=0. Let v(x):=y'(x). Put in
y'(x)=v,
v'(x)=-0.2v-sin(y).
Now choose v(y) (phase space) instead of y(x). Put in
x0=0,
y(x0)=-10:10,
v(x0)=0.
<b>Grapher for sequences</b>
Recursion is possible. Take the recursive definition
f(n) = if n=0 then 1 else 2f(n-1)
as an example. This has to be written in the form
f(n) = if(n=0,1,2f(n-1)).
In the calculator line it is written in the form
p:=fix({f,n|if(n=0,1,2f(n-1))}).
The function fix will memoize the values. Define
fib:=fix({f,n|if(n=1|n=2,1,f(n-1)+f(n-2))}).
Now fib(40) will be calculated efficiently. Otherwise
the number of calculations would be in O(2^n).
The function sum(f,a,b) can be used to define a series.
The input for sum(from k=1 to n) 1/k is
f(n) = sum({k|1/k},1,n)
or also
f(n) = 1/n,
g(n) = sum(f,1,n).
<b>Grapher for complex valued functions</b>
Let us take the function f(x) = exp(i*x) as an example.
The real part is expressed with
f(x) = exp(i*x) or also with f(x) = re(exp(i*x)).
Analogously the the imaginary part is
g(x) = im(exp(i*x))
and the absolute value is
h(x) = abs(exp(i*x)).
<b>Grapher for fractals</b>
It is also possible to draw Julia sets.
For example put in f(z)=z^2-1 and z0=c.
r: out of bound radius
n: maximum number of iterations
</pre>
<h2 id="Examples">
Examples</h2>
<pre>
Tangent line:
g(x) = diff(f,a)(x-a)+f(a)
Normal line:
h(x) = -1/diff(f,a)(x-a)+f(a)
Restriction of f to the interval (0,1):
g(x) = if(0<x&x<1,f(x),nan)
Function f on support (0,1):
g(x) = if(0<x&x<1,f(x),0)
g(x) = f(x)(x>0)(x<1)
Partial sum of the power series of the exponential function:
f(x) = sum({k|x^k/fac(k)},0,20)
Gamma function via parameter integral:
f(x) = int({t|t^(x-1)*exp(-t)},0,10)
Bifurcation diagramm for the logistic map:
f(x) = {r|pow({x|r*x*(1-x)},40,rand(0,1))}(x)
Mandelbrot set:
f(z) = {c|pow({z|z^2+c},10,0)}(z)
Newton fractal of x^3-1=0:
f(z) = pow({x|x-(x^3-1)/(3x^2)},10,z)
Click with the mouse in one of the basins to get the
corresponding root.
Table of prime numbers:
filter(isprime,1:100)
Count the number of primes:
count(isprime,1:100)
Twin primes:
filter({k|isprime(k)&(isprime(k+2)|isprime(k-2))},1:100)
Prime factorization of the numbers from 1 to 100:
table(factor,1:100)
Find cyclic multiplicative groups of integers:
filter({n|phi(n)=lambda(n)},1:100)
Continued fraction representation of the exponential function:
f(x) = 1+x/(1-reduce({t,k|x/k/(1+x/k-t)},rev(2:10)))
Interpolation polynomial of tanh:
f(x) = p(x); p:=ipp(table(tanh,-6:6))
</pre>
<h2 id="Advanced">
Advanced</h2>
<pre>
<b>Defining functions</b>
The calculator line is not just of use for calculating values,
but also for defining an arbitrary number of functions and
constants. For example, write the input
p:={x|2*x}
and press the calc-button.
Now p(x) is available everywhere.
To define the function permanently, add the line
evals("p:={x|2*x}");
to the end of the file "plot.js". If the function has to be
complex, add the line
evalsc("p:={x|2*x}");
to the end of the file "cplot.js" instead.
A function may be programmed in JavaScript to extend the list
of predefined functions. To achieve the function is available,
add the following code to the end of the file "plot.js".
function p(x){
return 2*x;
}
ftab.p=p;
<b>Functions with two arguments</b>
If you want to have the function p(x,y)=x*y, define p:={x,y|x*y}
in the calculator line and press the calc-button.
Alternatively define a function that takes a list instead.
So define in the calculator line p:={a|get(a,1)*get(a,2)}.
Therefore the function application is written p([x,y])
and not p(x,y).
<b>Domain of a function</b>
To draw the function f(x)=sin(x) only in the interval (0,2pi), write
f(x) = if(0<x&x<2pi,sin(x),nan).
The expression stands for
if 0<x and x<2pi, then sin(x), else not a number.
<b>Solving equations</b>
The equation f(x)=0 with f(x)=e^x+x^3-2x has to be solved. A plot
shows a zero of f in the interval [-2,-1] and that f is injective
in this interval. Therefore it is possible to draw the inverse
function with g(x)=inv(f,x,-2,-1). Now the zero is simply g(0).
To calculate the value, type g(0) in the calculator line.
<b>Tables</b>
To tabulate the function f(x)=x^2 on the intervall [0,4], write
table({x|x^2},0:4:0.1)
in the calculator line. The input is equivalent to
map({x|[x,x^2]},0:4:0.1).
<b>Random numbers</b>
Random numbers following a particular distribution are generated by
the inversion method. Firstly graph the function f(x) = inv(norm,x).
Now calculate f(rand(0,1)) in the calculator line. The results
are normal distributed random numbers. Now define
a:=map({k|f(rand(0,1))},1:1000).
The function g(x) = cdf(a,x) will show the cumulative distribution
function for the random numbers in the list a.
<b>Colors</b>
With color(r,g,b) a function can be drawn in another color.
Each of the values r,g,b goes from 0 to 255.
If a number is too big oder negative, it is restricted
to the intervall from 0 to 255.
For example, you can write
f(x) = sin(x), color(220,180,0).
Then the function will be drawn in yellow.
If bcolor(r,g,b) is calculated in the calculator line,
the background color of the canvas screen will be changed.
<b>Number of pixels</b>
If setw(1080) is calculated in the calculator line,
the width of the canvas screen will be increased to 1080 pixels.
The statement setw(w,h) will change width and height independently.
<b>Coordinate system</b>
The input of sp(x,y) (set position) in the calculator line
changes the origin of the coordinate system to the
pixel position (x,y).
In case there is a selection, "manual" has to be chosen.
<b>Mouse</b>
A click with the mouse on the canvas screen saves the
coordinates pointed to in the variables mx and my.
Thereafter it is possible to evaluate f(mx) in the calculator line.
<b>Vertical lines</b>
If the input is
f(x) = 1/(x-2)/(x-4); vline(2,4),
vertical lines at the points x=2 and x=4
will be drawn in addition to the graph.
<b>Discontinuities</b>
The example
f(x) = sgn(x); scatter([0,0]); box([0,1],[0,-1])
shows how to picture singular points and the absence of points.
A more complicated example:
f(x) = floor(x);
scatter(map({x|[x,x]},-6:6)),
box(map({x|[x+1,x]},-6:6))
<b>Piecewise linear interpolation</b>
Example:
f(x) = p(x); p:=fn([[0,0],[1,1],[2,0],[3,-1],[4,0]])
<b>Piecewise linear interpolation, equidistant nodes</b>
The last example has equidistant nodes. So one can use
a simpler algorithm. The usage is:
fn(x0,d,[y0,y1,y2,y3,...,yn])
That means, we have points:
[x0,y0], [x0+d,y1], [x0+2d,y2], [x0+3d,y3], ..., [x0+n*d,yn]
The last example simplifies to:
f(x) = p(x); p:=fn(0,1,[0,1,0,-1,0])
<b>Linear regression</b>
Let a be a list of points [x,y].
Now t:=rl(a) calculates a linear regression and we have:
y = t.ax*x+t.bx = t.ax*(x-t.mx)+t.my
x = t.ay*y+t.bx = t.ay*(y-t.my)+t.mx
t.mx: x mean
t.my: y mean
t.c: [t.mx,t.my] (center)
r: sample correlation coefficient
Example:
f(x) = p(x);
a:=[[0,0],[1,2],[2,1],[3,4],[4,3],[5,4]],
p:=fn(a), scatter(a), t:=rl(a), box(t.c)
g(x) = t.ax*x+t.bx
h(x) = (x-t.by)/t.ay
<b>Saving images</b>
The instruction save() generates an image of the canvas screen,
that can be saved. In some browsers the canvas screen
itself can be saved as an image. In this case, it is not necessary
to use save().
<b>Animations</b>
We want the amplitude of the sine function to swing between
-1 and 1. Define f(x) = r:=sin(a/10), r*sin(x). Now write ani() in
the calculator line and press the calc-button.
<b>Closures</b>
If you write {x;T(x)} instead of {x|T(x)}, a closure is created,
provied the anonymous function is contained in the term of another
anonymous function.
Let the continued fraction representation of the exponential
function serve as an example. Define
p:=compose(map({k|{t;x/k/(1+x/k-t)}},2:10))
in the calculator line and press the calc-button.
The approximation of the exponential function is
f(x) = 1+x/(1-p(0)).
</pre>
</body>
</html>