1 | ### defint =====================================================================
|
2 |
|
3 | Tags
|
4 | ----
|
5 | scripting, JS, internal, treenode, general concept
|
6 |
|
7 | Parameters
|
8 | ----------
|
9 | f,x,a,b[,y,c,d...]
|
10 |
|
11 | General description
|
12 | -------------------
|
13 | Returns the definite integral of f with respect to x evaluated from "a" to b.
|
14 | The argument list can be extended for multiple integrals (or "iterated
|
15 | integrals"), for example a double integral (which can represent for
|
16 | example a volume under a surface), or a triple integral, etc. For
|
17 | example, defint(f,x,a,b,y,c,d).
|
18 |
|
19 | ###
|
20 |
|
21 |
|
22 |
|
23 | #define F p2
|
24 | #define X p3
|
25 | #define A p4
|
26 | #define B p5
|
27 |
|
28 | Eval_defint = ->
|
29 | push(cadr(p1))
|
30 | Eval()
|
31 | p2 = pop() # p2 is F
|
32 |
|
33 | p1 = cddr(p1)
|
34 |
|
35 | # defint can handle multiple
|
36 | # integrals, so we loop over the
|
37 | # multiple integrals here
|
38 | while (iscons(p1))
|
39 |
|
40 | push(car(p1))
|
41 | p1 = cdr(p1)
|
42 | Eval()
|
43 | p3 = pop() # p3 is X
|
44 |
|
45 | push(car(p1))
|
46 | p1 = cdr(p1)
|
47 | Eval()
|
48 | p4 = pop() # p4 is A
|
49 |
|
50 | push(car(p1))
|
51 | p1 = cdr(p1)
|
52 | Eval()
|
53 | p5 = pop() # p5 is B
|
54 |
|
55 | # obtain the primitive of F against the
|
56 | # specified variable X
|
57 | # note that the primitive changes over
|
58 | # the calculation of the multiple
|
59 | # integrals.
|
60 | push(p2)
|
61 | push(p3)
|
62 | integral()
|
63 | p2 = pop() # contains the antiderivative of F
|
64 |
|
65 | # evaluate the integral in A
|
66 | push(p2)
|
67 | push(p3)
|
68 | push(p5)
|
69 | subst()
|
70 | Eval()
|
71 |
|
72 | # evaluate the integral in B
|
73 | push(p2)
|
74 | push(p3)
|
75 | push(p4)
|
76 | subst()
|
77 | Eval()
|
78 |
|
79 | # integral between B and A is the
|
80 | # subtraction. Note that this could
|
81 | # be a number but also a function.
|
82 | # and we might have to integrate this
|
83 | # number/function again doing the while
|
84 | # loop again if this is a multiple
|
85 | # integral.
|
86 | subtract()
|
87 | p2 = pop()
|
88 |
|
89 | push(p2)
|
90 |
|
91 |
|