File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,6 +42,8 @@ It's always fun to start out with a tutorial before jumping into the details!
4242Suppose we had the functions:
4343
4444``` julia
45+ using FiniteDiff, StaticArrays
46+
4547fcalls = 0
4648function f (dx,x) # in-place
4749 global fcalls += 1
@@ -53,11 +55,12 @@ function f(dx,x) # in-place
5355 nothing
5456end
5557
58+ const N = 10
5659handleleft (x,i) = i== 1 ? zero (eltype (x)) : x[i- 1 ]
5760handleright (x,i) = i== length (x) ? zero (eltype (x)) : x[i+ 1 ]
5861function g (x) # out-of-place
5962 global fcalls += 1
60- @SVector [handleleft (x,i) - 2 x[i] + handleright (x,i) for i in 1 : length (x) ]
63+ @SVector [handleleft (x,i) - 2 x[i] + handleright (x,i) for i in 1 : N ]
6164end
6265```
6366
@@ -66,8 +69,7 @@ do is ask for the Jacobian. If we want to allocate the result, we'd use the
6669allocating function ` finite_difference_jacobian ` on a 1-argument function ` g ` :
6770
6871``` julia
69- using StaticArrays
70- x = @SVector rand (10 )
72+ x = @SVector rand (N)
7173FiniteDiff. finite_difference_jacobian (g,x)
7274
7375#=
You can’t perform that action at this time.
0 commit comments