rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
calculate_derivative.m
Go to the documentation of this file.
1 function U_der = calculate_derivative(model, model_data)
2 %function U_der = calculate_derivative(model, model_data)
3 %Function calculates the derivative of the function U using detailed
4 %simulation.
5 %
6 % This function is meant for verification of the calculation of the
7 % derivative using reduced simulations.
8 %
9 % Markus Dihlmann 25.06.2010
10 %
11 
12 
13 mu0 = get_mu(model);
14 U_der = zeros(size(model_data.W,1),model.nt+1,length(get_mu_to_optimize(model)));
15 i=0;
16 h_range = 100; % for constructing the difference quotient: how small is the variaton of the parameter
17 
18  sim_data = detailed_simulation(model, model_data);
19  U0 = sim_data.U;
20 
21  for k=1:length(mu0)
22  h = (model.mu_ranges{k}(2)-model.mu_ranges{k}(1))/h_range; % ranges must be intervals
23  if model.optimization.params_to_optimize(k) == 1
24  i=i+1;
25  if model.mu_ranges{k}(2)-mu0(k) >= h % is it possible to get the righthanded difference quotient?
26  mu0(k) = mu0(k)+h;
27  model = set_mu(model,mu0);
28  sim_data = detailed_simulation(model, model_data); %value of the functional after changing one parameter
29  U_der(:,:,i) = (1/h) * (sim_data.U-U0);
30  mu0(k) = mu0(k)-h;
31  model = set_mu(model,mu0);
32  else
33  mu0(k) = mu0(k)-h;
34  model = set_mu(model,mu0);
35  sim_data = detailed_simulation(model, model_data); %value of the functional after changing one parameter
36  U_der(:,:,i) = (1/h) * (-sim_data.U+U0);
37  mu0(k) = mu0(k)+h;
38  model = set_mu(model,mu0);
39  end
40 
41  end
42  end
43 
function U_der = calculate_derivative(model, model_data)
Function calculates the derivative of the function U using detailed simulation.