-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathdefint.coffee
More file actions
91 lines (71 loc) · 1.64 KB
/
defint.coffee
File metadata and controls
91 lines (71 loc) · 1.64 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
### defint =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
f,x,a,b[,y,c,d...]
General description
-------------------
Returns the definite integral of f with respect to x evaluated from "a" to b.
The argument list can be extended for multiple integrals (or "iterated
integrals"), for example a double integral (which can represent for
example a volume under a surface), or a triple integral, etc. For
example, defint(f,x,a,b,y,c,d).
###
#define F p2
#define X p3
#define A p4
#define B p5
Eval_defint = ->
push(cadr(p1))
Eval()
p2 = pop() # p2 is F
p1 = cddr(p1)
# defint can handle multiple
# integrals, so we loop over the
# multiple integrals here
while (iscons(p1))
push(car(p1))
p1 = cdr(p1)
Eval()
p3 = pop() # p3 is X
push(car(p1))
p1 = cdr(p1)
Eval()
p4 = pop() # p4 is A
push(car(p1))
p1 = cdr(p1)
Eval()
p5 = pop() # p5 is B
# obtain the primitive of F against the
# specified variable X
# note that the primitive changes over
# the calculation of the multiple
# integrals.
push(p2)
push(p3)
integral()
p2 = pop() # contains the antiderivative of F
# evaluate the integral in A
push(p2)
push(p3)
push(p5)
subst()
Eval()
# evaluate the integral in B
push(p2)
push(p3)
push(p4)
subst()
Eval()
# integral between B and A is the
# subtraction. Note that this could
# be a number but also a function.
# and we might have to integrate this
# number/function again doing the while
# loop again if this is a multiple
# integral.
subtract()
p2 = pop()
push(p2)