Mercurial > repos > public > sbplib
comparison +noname/calculateErrors.m @ 704:111fcbcff2e9 feature/optim
merg with featuew grids
author | Ylva Rydin <ylva.rydin@telia.com> |
---|---|
date | Fri, 03 Nov 2017 10:53:15 +0100 |
parents | 818d52d4928f |
children | b59345f905f0 |
comparison
equal
deleted
inserted
replaced
703:027f606fa691 | 704:111fcbcff2e9 |
---|---|
1 % [discr, trueSolution] = schemeFactory(m) | |
2 % where trueSolution should be a timeSnapshot of the true solution a time T | |
3 % T is the end time | |
4 % m are grid size parameters. | |
5 % N are number of timesteps to use for each gird size | |
6 % timeOpt are options for the timeStepper | |
7 function e = calculateErrors(schemeFactory, T, m, N, errorFun, timeOpt) | |
8 assertType(schemeFactory, 'function_handle'); | |
9 assertNumberOfArguments(schemeFactory, 1); | |
10 assertScalar(T); | |
11 assert(length(m) == length(N), 'Vectors m and N must have the same length'); | |
12 assertType(errorFun, 'function_handle'); | |
13 assertNumberOfArguments(errorFun, 2); | |
14 default_arg('timeOpt'); | |
15 | |
16 e = []; | |
17 for i = 1:length(m) | |
18 done = timeTask('m = %3d ', m(i)); | |
19 | |
20 [discr, trueSolution] = schemeFactory(m(i)); | |
21 | |
22 timeOpt.k = T/N(i); | |
23 ts = discr.getTimestepper(timeOpt); | |
24 ts.stepTo(N(i), true); | |
25 approxSolution = discr.getTimeSnapshot(ts); | |
26 | |
27 e(i) = errorFun(trueSolution, approxSolution); | |
28 | |
29 fprintf('e = %.4e', e(i)) | |
30 done() | |
31 end | |
32 fprintf('\n') | |
33 end | |
34 | |
35 | |
36 %% Example error function | |
37 % u_true = grid.evalOn(dr.grid, @(x,y)trueSolution(T,x,y)); | |
38 % err = u_true-u_false; | |
39 % e(i) = norm(err)/norm(u_true); | |
40 % % e(i) = sqrt(err'*d.H*d.J*err/(u_true'*d.H*d.J*u_true)); |