
% startup
if (exist('initDone')==0),
	% startup TOMLAB
	addpath c:\tomlab;
	startup;

	% add bin folder to Matlab path and initialize RTC Tools
	addpath('../../../x86-windows-vc-9.0/bin/release');
	
	initDone = 1;
end


% initialize RTC Tools
RTCToolsMatlab('initialize');

% initial guess for controlled variable
load controlvector;
input = Dirkcontrolvector;

% simulation and cost function evaluation
[j] = RTCToolsMatlab(input);

% problem definition
Prob = conAssign('jRes', 'jResDer', [], [], 0*ones(344,1), 0.00369444*ones(344,1), 'Name', input, [], [], [], [], []);
Prob.SOL.optPar(10) = 0.00001;

% derivative check
[exitFlag,output] = checkDerivs(Prob, input, 1, 1, [], []);

% first optimization
tic
Result = tomRun('snopt', Prob, 1);
time=toc

% change parameters, in this case the storage area
% check for the files 'rtcParameterConfig.xml' and 'rtcToolsConfig.xml'
RTCToolsMatlab('DA mode');
[j] = RTCToolsMatlab(1330)
[j] = RTCToolsMatlab(2660)
RTCToolsMatlab('MPC mode');

% second optimization
tic
Result = tomRun('snopt', Prob, 1);
time=toc

% close RTC Tools
RTCToolsMatlab('close');