function [fitted_vals,resnorm,residual]=facilitation_depression_model%(timings, values)

%this is a fascinating, deterministic model of the function of a synapse
%here we work with charge
%we ignore:  latency, rise time, decay time, release probability, variance in charge, release dependence, jittered releases...

% PSC_o=1
% 
% PSC_a25=1.5
% PSC_a50=1.4
% PSC_a100=1.2
% PSC_a200=1
% PSC_a400=.8

facil=2
tau_facil=30
depress=.8
tau_depress=50

timmes=[25 50 100 200 400]
% chargges=[1 1.5 1.4 1.2 1 .8]
% chargges=[4.26 3.9250 2.0311 9.5370 3.0633 2.1933]
% chargges=[ 5.7945 7.0812 4.1801 7.1335 3.4841 7.0771]
% chargges=[5.5299 13.6289 12.3206 19.1488 5.8613 2.7300]
% chargges=chargges./chargges(1)
% chargges=chargges(2:end)
chargges=[0.7278    1.1427    3.6497    1.1005    1.2262]

seed_values=[facil tau_facil depress tau_depress];
time_vector=[1:400];

lower_bounds=[0 1 0 1];
upper_bounds=[100 5000 100 1000];
%fittingz_this_trial=[];
optionz=optimset('display','off');

%facil_depress_curve=facil_depress_curvegenerator(seed_values,timmes);
%plot(facil_depress_curve,'k'),hold on

options=optimset('MaxFunEvals',10000)


%[best_fitted_vals,best_resnorm,best_residual]=lsqcurvefit(@lsqfit_template_generator,seed_vals,[1:length(trace)],trace',lower_bounds,upper_bounds,optionz);

[fitted_vals,resnorm,residual]=lsqcurvefit(@facil_depress_curvegenerator,seed_values,timmes,chargges,lower_bounds,upper_bounds,options);
%     if resnorm<best_resnorm,best_fitted_vals=fitted_vals;best_residual=residual;best_resnorm=resnorm;end

plot([0 timmes],[1 chargges],'rs'),hold on
facil_depress_curve=facil_depress_curvegenerator(fitted_vals,time_vector);
plot(facil_depress_curve,'r:')