-
Notifications
You must be signed in to change notification settings - Fork 0
/
gradient_fit_normalized_3param.m
48 lines (42 loc) · 2.4 KB
/
gradient_fit_normalized_3param.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function [fitresult, gof] = gradient_fit_normalized_3param(F_DBS_, I_inf,x0, ub, lb,U,T_syn,MaxIter,mode)
%CREATEFIT(F_DBS_,I_INF)
% Create a fit.
%
% Data for 'close_form_sol' fit:
% X Input : F_DBS_
% Y Output: I_inf
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%
% See also FIT, CFIT, SFIT.
% Auto-generated by MATLAB on 15-Feb-2021 18:25:09
f0=x0(1);
D0=x0(2);
F0=x0(3);
%% Fit: 'close_form_sol'.
[xData, yData] = prepareCurveData( F_DBS_, I_inf );
% /(',num2str(U),'*(1-f)+f)
if strcmp(mode,'Normal') %% normal
Formula=['((f+',num2str(U),'*(1-f)*(1-exp(-1./(x*F))))/(1-(1-f)*exp(-1./(x*F))))*((1-exp(-1./(x*D)))/(1-(1-(f+',num2str(U),'*(1-f)*(1-exp(-1./(x*F))))/(1-(1-f)*exp(-1./(x*F))))*exp(-1./(x*D))))/(1-exp(-1./(x*',num2str(T_syn),')))'];%*
elseif strcmp(mode,'AllLog')%% all log--> /(exp(',num2str(U),')*(1-exp(f))+exp(f))
Formula=['((exp(f)+exp(',num2str(U),')*(1-exp(f))*(1-exp(-1./(x*exp(F)))))/(1-(1-exp(f))*exp(-1./(x*exp(F)))))*((1-exp(-1./(x*exp(D))))/(1-(1-(exp(f)+exp(',num2str(U),')*(1-exp(f))*(1-exp(-1./(x*exp(F)))))/(1-(1-exp(f))*exp(-1./(x*exp(F)))))*exp(-1./(x*exp(D)))))/(1-exp(-1./(x*',num2str(T_syn),')))'];%/(exp(U)*(1-exp(f))+exp(f))*
elseif strcmp(mode,'HalfLog')%% only f and U are log
Formula=['((exp(f)+exp(',num2str(U),')*(1-exp(f))*(1-exp(-1./(x*F))))/(1-(1-exp(f))*exp(-1./(x*F))))*((1-exp(-1./(x*D)))/(1-(1-(exp(f)+exp(',num2str(U),')*(1-exp(f))*(1-exp(-1./(x*F))))/(1-(1-exp(f))*exp(-1./(x*F))))*exp(-1./(x*D))))/(exp(',num2str(U),')*(1-exp(f))+exp(f))/(1-exp(-1./(x*',num2str(T_syn),')))'];%(exp(U)*(1-exp(f))+exp(f))*
end
% Set up fittype and options.
ft = fittype( Formula, 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares','MaxIter',MaxIter);
opts.Display = 'Off';
opts.Lower = [lb(2:3),lb(1)];%[0 0 0 0];
opts.StartPoint = [F0, D0,f0]; %[0.855027860168076 0.806963747508719 0.156395362862094 0.133170887149803];
opts.Upper = [ub(2:3),ub(1)];%[2 2 1 1];
[fitresult, gof] = fit( xData, yData, ft, opts );
% % Plot fit with data.
% figure( 'Name', 'close_form_sol' );
% h = plot( fitresult, xData, yData );
% legend( h, 'I_inf vs. F_DBS_', 'close_form_sol', 'Location', 'NorthEast', 'Interpreter', 'none' );
% % Label axes
% xlabel( 'F_DBS_', 'Interpreter', 'none' );
% ylabel( 'I_inf', 'Interpreter', 'none' );
% grid on