|
111 | 111 | @test gnewton(p) ≈ [sqrt(p[2] / p[1])] |
112 | 112 | @test ForwardDiff.jacobian(gnewton, p) ≈ ForwardDiff.jacobian(t, p) |
113 | 113 |
|
| 114 | +# Iterator interface |
| 115 | +f = (u, p) -> u * u - p |
| 116 | +g = function (p_range) |
| 117 | + probN = NonlinearProblem{false}(f, 0.5, p_range[begin]) |
| 118 | + cache = init(probN, NewtonRaphson(); maxiters = 100, abstol=1e-10) |
| 119 | + sols = zeros(length(p_range)) |
| 120 | + for (i, p) in enumerate(p_range) |
| 121 | + reinit!(cache, cache.u; p = p) |
| 122 | + sol = solve!(cache) |
| 123 | + sols[i] = sol.u |
| 124 | + end |
| 125 | + return sols |
| 126 | +end |
| 127 | +p = range(0.01, 2, length = 200) |
| 128 | +@test g(p) ≈ sqrt.(p) |
| 129 | + |
| 130 | +f = (res, u, p) -> (res[begin] = u[1] * u[1] - p) |
| 131 | +g = function (p_range) |
| 132 | + probN = NonlinearProblem{true}(f, [0.5], p_range[begin]) |
| 133 | + cache = init(probN, NewtonRaphson(); maxiters = 100, abstol=1e-10) |
| 134 | + sols = zeros(length(p_range)) |
| 135 | + for (i, p) in enumerate(p_range) |
| 136 | + reinit!(cache, [cache.u[1]]; p = p) |
| 137 | + sol = solve!(cache) |
| 138 | + sols[i] = sol.u[1] |
| 139 | + end |
| 140 | + return sols |
| 141 | +end |
| 142 | +p = range(0.01, 2, length = 200) |
| 143 | +@test g(p) ≈ sqrt.(p) |
| 144 | + |
114 | 145 | # Error Checks |
115 | 146 |
|
116 | 147 | f, u0 = (u, p) -> u .* u .- 2.0, @SVector[1.0, 1.0] |
|
0 commit comments