- Author:
- Shelley Fong <s.fong@auckland.ac.nz>
- Date:
- 2022-04-20 10:56:13+12:00
- Desc:
- storing gate particle number in comp environment
- Permanent Source URI:
- http://models.cellml.org/workspace/823/rawfile/9d6719177e83db1f7662b4a271f68cf38ae67094/matlab_parameter_fitting/K_IV_curve.m
clear;
% clc;
% close all;
%% Options
run_optimisation = true;
%% Set up directories
current_dir = cd;
Idx_backslash = find(current_dir == filesep);
main_dir = current_dir(1:Idx_backslash(end));
data_dir = ['data' filesep];
code_dir = ['code' filesep];
output_dir = ['output' filesep];
storage_dir = ['storage' filesep];
%% Define constants
R = 8.314;
T = 310;
F = 96485;
P_NaK = 0.01833;
%% Plot I-V curves
cKo_st = 5.4;
cKo = 5.4;
cKi_st = 145;
A_geo = 1.1e-5; %Kernik (Hwang) 1.534e-4; % Unit cm^2
G_K = 0.282*A_geo*sqrt(cKo/5.4); % Unit mA/V [=] mSiemens
V = (-120:1:60)/1000;
E_K = R*T/F*log(cKo/cKi_st);
I_lin = G_K*(V-E_K); % Unit mA
error_func = @(G_GHK) square_error(I_lin(V>=-0.02 & V<0.03) - calc_IGHK(G_GHK,V(V>=-0.02 & V<0.03),cKi_st,cKo));
A = [];
b = [];
Aeq = [];
beq = [];
lb = [-Inf];
ub = [Inf];
options_ps = optimoptions('particleswarm','UseParallel',false,'HybridFcn',@fminunc,'SwarmSize',200);
if run_optimisation
[G_GHK,fval,exitflag,output] = particleswarm(error_func,1,lb,ub,options_ps);
save([storage_dir 'K_G_GHK.mat'],'G_GHK');
else
load([storage_dir 'K_G_GHK.mat']);
end
I_GHK = calc_IGHK(G_GHK,V,cKi_st,cKo);
h = figure;
plot(1000*V,1e6*I_lin,'k--',1000*V,1e6*I_GHK,'k','LineWidth',2);
legend('LRd','BG','Location','southeast');
ylabel('Current (nA)');
xlabel('Voltage (mV)');
set(gca,'FontSize',16);
grid on
diff = sum(abs((I_lin-I_GHK)./I_lin));
% print_figure(h,output_dir,'K_IV_curve');