rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
lin_evol_opt_fd_second_derivative.m
1 function U_der2 = lin_evol_opt_fd_second_derivative(model, model_data, mu,h)
2 %function U_der = lin_evol_opt_fd_second_derivative(model, model_data, mu,h)
3 %
4 % function calculating the second derivative solution via PDE and finite difference
5 % procedure for the parameter mu.
6 %
7 % Markus Dihlmann 03.02.2011
8 
9 if isempty(mu)
10  mu = get_mu(model);
11 end
12 
13 old_mu = get_mu(model);
14 
15 
16 
17 compute_derivative_old = model.compute_derivative_info;
18 
19 model.compute_derivative_info =1;
20 
21 
22 sim_data = detailed_simulation(model, model_data);
23 
24 U_der_fix=sim_data.U_der;
25 U_der2 = cell(1,length(mu));
26 if (nargin<4)
27  h=0.01; %stepsize
28 end
29 
30 for i=1:length(mu)
31  %is mu+h inside mu_range?
32  if (mu(i)+h>=model.mu_ranges{i}(1))&&(mu(i)+h<=model.mu_ranges{i}(2))
33  mu(i) = mu(i) + h;
34  model = set_mu(model,mu);
35  sim_data = detailed_simulation(model, model_data);
36  mu(i) = mu(i) -h;
37  model = set_mu(model,mu);
38 
39  U_der2{i} = (sim_data.U_der{i}-U_der_fix{i})./h;
40  else
41  mu(i) = mu(i) - h;
42  model = set_mu(model,mu);
43  sim_data = detailed_simulation(model, model_data);
44  mu(i) = mu(i) +h;
45  model = set_mu(model,mu);
46 
47  U_der2{i} = (-sim_data.U_der{i}+U_der_fix{i})./h;
48  end
49 
50 end
51 
52 model = set_mu(model, old_mu);
53 model.compute_derivative_info = compute_derivative_old;