Skip to contents

TestSolution(t, u) holds reference values u (a list of states, or a matrix with one row per time) at the times t; TestSolution(t, u, interp) adds an interpolating function interp(ts) (such as a solution), and TestSolution(sol) wraps the interpolation of a solution alone.

Usage

TestSolution(t, u = NULL, interp = NULL)

appxtrue(sol, sol2, timeseries_errors = NULL, dense_errors = NULL, ...)

Arguments

t

Times, or a solution for TestSolution(sol).

u

Reference values.

interp

Interpolating function of the times.

sol

A solution or an EnsembleSolution.

sol2

The reference: a TestSolution, a solution or, for an ensemble, a list of solver options with the algorithm alg.

timeseries_errors, dense_errors

Which errors to compute against a reference solution.

...

Options of the ensemble errors.

Value

TestSolution() returns a TestSolution; appxtrue() a solution with errors (an EnsembleTestSolution for an ensemble).

Details

appxtrue(sol, ref) computes the errors of the solution sol against the reference ref (a TestSolution or a solution): the final error (the mean absolute difference at the end), the timeseries errors l2 and l_inf at the times of sol and the dense errors L2 and L_inf at 100 equally spaced times. Without an interpolation of the reference only the final error is computed, plus the timeseries errors when the times agree. It returns a copy of sol whose errors and u_analytic fields hold the errors and the reference values. For a reference solution, timeseries_errors and dense_errors default to whether it is dense.

For an EnsembleSolution of SDE trajectories, appxtrue(sim, setup) solves each trajectory again on its own Brownian path with the algorithm setup$alg and the other options of setup, and returns the ensemble errors of the trajectories against those solutions (with the options weak_timeseries_errors and weak_dense_errors in ...).

Examples

f <- function(u, p, t) -u
prob <- ODEProblem(f, 1, c(0, 1))
sol <- solve(prob, Euler(), dt = 1 / 8)
ref <- solve(prob, RK4(), dt = 1 / 64)
appxtrue(sol, ref)$errors
#> $final
#> [1] 0.02427343
#> 
#> $l2
#> [1] 0.01877967
#> 
#> $l_inf
#> [1] 0.02427343
#> 
#> $L2
#> [1] 0.01892992
#> 
#> $L_inf
#> [1] 0.02454537
#> 
appxtrue(sol, TestSolution(ref))$errors$final
#> [1] 0.02427343