rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
eop_C_L_I.m
Go to the documentation of this file.
1 function model = eop_C_L_I(model)
2 %model = eop_C_L_I(model)
3 %
4 % function to compute and empirical continuousity constant of the Matrix
5 % L_I^-1 of a linear evolution scheme. Required for the nomal L2-error
6 % estimator.
7 
8 % computes the largest magnitude of ||L_I^-1|| for all \mu\in M_train and
9 % takes the maximum of those as empirical continuousity constant.
10 
11 % Dominik Garmatter 11.03 2012
12 
13 model_data = gen_model_data(model);
14 
15 % get the components of L_I
16 model.decomp_mode = 1;
17 [L_I_comp, ~, ~] = model.operators_ptr(model, model_data);
18 
19 % formt he Training set Mtrain as a discretisation of the parameter space
20 par.numintervals = model.RB_numintervals-2;
21 par.range = model.mu_ranges;
22 diskret_par_space = cubegrid(par);
23 Mtrain = get(diskret_par_space, 'vertex')';
24 
25 spectral_build = zeros(size(Mtrain,2),1);
26 n = size(L_I_comp{1},1);
27 
28 % build vector
29 for i = 1:size(Mtrain,2)
30  disp(i)
31  % assemble L_I for the current mu
32  model = model.set_mu(model,Mtrain(:,i));
33  model.decomp_mode = 2;
34  [L_I_coeff, ~, ~] = model.operators_ptr(model, model_data);
35  L_I = lincomb_sequence(L_I_comp,L_I_coeff);
36  % compute the largest magnitude
37  spectral_build(i) = eigs(@(x)my_mult_for_L_I(x,L_I,model_data.W),n,1,'LM');
38  try %first try to solve the EWP with default tolerance eps
39  spectral_build(i) = eigs(@(x)my_mult_for_L_I(x, L_I, model_data.W), n, model_data.W, 1,'LM');
40  catch err
41  if (strcmp(err.identifier,'MATLAB:eigs:ARPACKroutineErrorMinus14')) %if no eigenvalues to sufficient accuracy was found reduce the tolerance and try it again
42  opts.tol = 1e-14;
43  no_solution = 1;
44  while no_solution
45  disp(['I reduced the tolerance of an eigenvalueproblem to ' mat2str(opts.tol)]);
46  try
47  spectral_build(i) = eigs(@(x)my_mult_for_L_I(x, L_I, model_data.W), n, model_data.W, 1,'LM',opts);
48  no_solution = 0; %end when there is no error
49  catch err2 %when it still fails reduce the tolerance and try again!
50  no_solution = 1;
51  if (strcmp(err2.identifier,'MATLAB:eigs:ARPACKroutineErrorMinus14'))
52  opts.tol = 100 * opts.tol;
53  end
54  if opts.tol > 1e-3 %if the tolerance is reduced until a certain value, give an error since the tolerance is too soft!
55  error(['I reduced the tolerance to ' mat2str(opts.tol) ' but I still could not find a solution. Reconsider your Problem']);
56  end
57  end
58  end
59  else %if there is another error rethrow
60  rethrow(err)
61  end
62  end
63 end
64 model.L_I_inv_norm_bound = max(spectral_build);
65 
66 
67 %==========================================================================
68 
69 
70 function y = my_mult_for_L_I(x,L,K)
71 % AFUN for eigs to compute ||(L_I)^-1(\mu)||_2.
72 % Does the operationy = K^-1/2 * L^-1 * K * L^-1 * K^-1/2 * x.
73 Kinv = sqrt(inv(K));
74 z1 = Kinv * x;
75 z2 = L\z1;
76 z3 = K*z2;
77 z4 = L\z3;
78 z5 = Kinv * z4;
79 y = z5;
A hierarchical cubegrid of arbitrary dimension.
Definition: cubegrid.m:17
function model = eop_C_L_I(model)
model = eop_C_L_I(model)
Definition: eop_C_L_I.m:17