June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,8 +1,16 @@
|
|||
function simpson(f, a,b, n)
|
||||
h = (b-a)/n
|
||||
s = f(a + h/2)
|
||||
function simpson(f::Function, a::Number, b::Number, n::Integer)
|
||||
h = (b - a) / n
|
||||
s = f(a + h / 2)
|
||||
for i in 1:(n-1)
|
||||
s += f(a + h*i + h/2) + 0.5 * f(a + h*i)
|
||||
s += f(a + h * i + h / 2) + f(a + h * i) / 2
|
||||
end
|
||||
h/6 * (f(a) + f(b) + 4*s)
|
||||
return h/6 * (f(a) + f(b) + 4*s)
|
||||
end
|
||||
|
||||
rst =
|
||||
simpson(x -> x ^ 3, 0, 1, 100),
|
||||
simpson(x -> 1 / x, 1, 100, 1000),
|
||||
simpson(x -> x, 0, 5000, 5_000_000),
|
||||
simpson(x -> x, 0, 6000, 6_000_000)
|
||||
|
||||
@show rst
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue