You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Added function to perform cumulative integrals, and array inputs (#15)
* (1) Added function cumul_integrate to perform cumulative integrals (similar to functions like cumtrapz in Matlab)
(2) Added methods to compute integrals and cumulative integrals for each column of an input Array
(3) updated documentation of functions
(4) updated readme
* Modified name of function for cumulative integrals to "cumul_integrate". New methods to integrate along specific dimensions of a matrix. Use Trapzedoial() (instead of TrapezoidalFast()) as default method, for safety.
Copy file name to clipboardExpand all lines: README.md
+17-3Lines changed: 17 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -16,22 +16,36 @@ Do note that while the code is trivial, it has not been extensively tested and d
16
16
```julia
17
17
# setup some data
18
18
x =collect(-π : π/1000: π)
19
-
y =sin(x)
19
+
y =sin.(x)
20
20
21
21
# integrate using the default TrapezoidalFast method
22
22
integrate(x, y)
23
23
24
24
# integrate using a specific method
25
25
integrate(x, y, SimpsonEven())
26
+
27
+
# compute cumulative integral
28
+
Y =cumul_integrate(x, y)
29
+
30
+
# compute cumulative integral for each column of an array
31
+
z = [sin.(x) cos.(x) exp.(x/pi)]
32
+
Z =cumul_integrate(x, z)
33
+
34
+
# compute cumulative integral for each line of an array
35
+
zp =permutedims(z)
36
+
ZP =cumul_integrate(x, zp, dims=1)
37
+
26
38
```
27
39
28
40
The currently available methods are:
29
-
- Trapezoidal
41
+
- Trapezoidal (default)
30
42
- TrapezoidalEven
31
-
- TrapezoidalFast (default)
43
+
- TrapezoidalFast
32
44
- TrapezoidalEvenFast
33
45
- SimpsonEven
34
46
- SimpsonEvenFast
35
47
- RombergEven
36
48
49
+
Only Trapezoidal methods are available for cumulative integrals.
50
+
37
51
All methods containing "Even" in the name assume evenly spaced data. All methods containing "Fast" omit basic correctness checks and focus on performance. Consequently, the fast methods will segfault or produce incorrect results if you supply incorrect data (vectors of different lengths, etc.). RombergEven needs a power of 2 + 1 points (so 9, 17, 33, 65, 129, 257, 513, 1025...) evenly spaced for it to work. Useful when control over accuracy is needed.
Compute numerical integral of y(x) from x=x[1] to x=x[end]. Return a scalar of the same type as the input. If not method is supplied, use TrapezdoialFast.
34
+
"""
35
+
functionintegrate(x,y...) end
36
+
37
+
38
+
"""
39
+
cumul_integrate(x,y...)
40
+
41
+
Compute cumulative numerical integral of y(x) from x=x[1] to x=x[end]. Return a vector with elements of the same type as the input. If not method is supplied, use TrapezdoialFast.
0 commit comments