Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 3.00 KB | None | 0 0
  1. %===simulation time===
  2. simulationTime = 100; %in milliseconds
  3. deltaT=.01;
  4. t=0:deltaT:simulationTime;
  5.  
  6.  
  7. %===specify the external current I===
  8. changeTimes = [0]; %in milliseconds
  9. currentLevels = [50]; %Change this to see effect of different currents on voltage (Suggested values: 3, 20, 50, 1000)
  10.  
  11. %Set externally applied current across time
  12. %Here, first 500 timesteps are at current of 50, next 1500 timesteps at
  13. %current of zero (resets resting potential of neuron), and the rest of
  14. %timesteps are at constant current
  15. I(1:500) = currentLevels; I(501:2000) = 0; I(2001:numel(t)) = currentLevels;
  16. %Comment out the above line and uncomment the line below for constant current, and observe effects on voltage timecourse
  17. %I(1:numel(t)) = currentLevels;
  18.  
  19.  
  20. %===constant parameters===%
  21. %All of these can be found in Table 3
  22. gbar_K=36; gbar_Na=120; g_L=.3;
  23. E_K = -12; E_Na=115; E_L=10.6;
  24. C=1;
  25.  
  26.  
  27. %===set the initial states===%
  28. V=0; %Baseline voltage
  29. alpha_n = .01 * ( (10-V) / (exp((10-V)/10)-1) ); %Equation 12
  30. beta_n = .125*exp(-V/80); %Equation 13
  31. alpha_m = .1*( (25-V) / (exp((25-V)/10)-1) ); %Equation 20
  32. beta_m = 4*exp(-V/18); %Equation 21
  33. alpha_h = .07*exp(-V/20); %Equation 23
  34. beta_h = 1/(exp((30-V)/10)+1); %Equation 24
  35.  
  36. n(1) = alpha_n/(alpha_n+beta_n); %Equation 9
  37. m(1) = alpha_m/(alpha_m+beta_m); %Equation 18
  38. h(1) = alpha_h/(alpha_h+beta_h); %Equation 18
  39.  
  40.  
  41. for i=1:numel(t)-1 %Compute coefficients, currents, and derivates at each time step
  42.    
  43.     %---calculate the coefficients---%
  44.     %Equations here are same as above, just calculating at each time step
  45.     alpha_n(i) = .01 * ( (10-V(i)) / (exp((10-V(i))/10)-1) );
  46.     beta_n(i) = .125*exp(-V(i)/80);
  47.     alpha_m(i) = .1*( (25-V(i)) / (exp((25-V(i))/10)-1) );
  48.     beta_m(i) = 4*exp(-V(i)/18);
  49.     alpha_h(i) = .07*exp(-V(i)/20);
  50.     beta_h(i) = 1/(exp((30-V(i))/10)+1);
  51.    
  52.    
  53.     %---calculate the currents---%
  54.     I_Na = (m(i)^3) * gbar_Na * h(i) * (V(i)-E_Na); %Equations 3 and 14
  55.     I_K = (n(i)^4) * gbar_K * (V(i)-E_K); %Equations 4 and 6
  56.     I_L = g_L *(V(i)-E_L); %Equation 5
  57.     I_ion = I(i) - I_K - I_Na - I_L;
  58.    
  59.    
  60.     %---calculate the derivatives using Euler first order approximation---%
  61.     V(i+1) = V(i) + deltaT*I_ion/C;
  62.     n(i+1) = n(i) + deltaT*(alpha_n(i) *(1-n(i)) - beta_n(i) * n(i)); %Equation 7
  63.     m(i+1) = m(i) + deltaT*(alpha_m(i) *(1-m(i)) - beta_m(i) * m(i)); %Equation 15
  64.     h(i+1) = h(i) + deltaT*(alpha_h(i) *(1-h(i)) - beta_h(i) * h(i)); %Equation 16
  65.  
  66. end
  67.  
  68.  
  69. V = V-70; %Set resting potential to -70mv
  70.  
  71. %===plot Voltage===%
  72. plot(t,V,'LineWidth',3)
  73. hold on
  74. legend({'voltage'})
  75. ylabel('Voltage (mv)')
  76. xlabel('time (ms)')
  77. title('Voltage over Time in Simulated Neuron')
  78.  
  79.  
  80. %===plot Conductance===%
  81. figure
  82. p1 = plot(t,gbar_K*n.^4,'LineWidth',2);
  83. hold on
  84. p2 = plot(t,gbar_Na*(m.^3).*h,'r','LineWidth',2);
  85. legend([p1, p2], 'Conductance for Potassium', 'Conductance for Sodium')
  86. ylabel('Conductance')
  87. xlabel('time (ms)')
  88. title('Conductance for Potassium and Sodium Ions in Simulated Neuron')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement