function [cost] = cost_function(Parameter)
%% defines the value which is to be optimised
% fmincon minimizes this value
global init_conc;
% global par;
global tspan;

% par = P; % P = Parameter
%% call model function, which calls the ordinary differential equation
dx = modell(tspan,Parameter);
%save the output of the differential equations in a file
save('dx.mat','dx')

%% optimise for the highest amount of degraded Hair at the endpoint of the simulation
cost = 1000 - dx((length(dx)),4); % when is most degraded

%% for optimisation after minimal time to have 10% of Hair degraded
% %  comment the above function and uncomment this part
% for i=1:length(dx)
% %     if (dx(i,4) < 100000/100*10) && dx(i,4) > 100000/(100+1)*10
%     if (dx(i,4) < (100000 + 100)) && (dx(i,4) > (100000 - 100)
%             value(1) = dx(i,4);
%             value(2) = i;
%     end 
% end
% 
% cost = value(2);



end
