Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 4.60 KB | None | 0 0
  1.  
  2. Δt= 0.001;  #the formula will work with timesteps of 0,001
  3. N= 200000;    #This will be the size of the array and subsequently the amount of integration steps. You divide (x*N)/Δt = amount of N needed for a certain timeframe.  
  4. C      = 1.;    # This is the membrane (specific) capacitance [uF/cm^2]
  5. gnamax = 120;   # This is the membrane max (specific) sodium conductance [mS/cm^2]
  6. gkmax  = 36;    # This is the membrane max (specific) potassium conductance [mS/cm^2]
  7. gl     = 0.3;   # This is the membrane max (specific) leak conductance [mS/cm^2]
  8. Ena    = 50.;     # This is the reversal potential for sodium currents [mV]
  9. Ek     = -77.;    # This is the reversal potential for potassium currents [mV]
  10. El     = -54.387; # This is the reversal potential for leak currents [mV]
  11. Iext   = 7;           #I played with the input current to find the current at which I started getting a train of AP's. There is a threshold at which the current injection causes an action potential to fire. This can be done by trial-and-error adjustment of the external current (Iext). This value lies between 2.2 and 2.25 (nA???) and should correlate with the value at which the frequency goes from 0 to any value higher than 0 in the FI-graph;
  12.  
  13. V= zeros(N,1); #This command will make the array defined by the number N earlier and fill it with zeros;
  14. m= zeros(N,1);
  15. n= zeros(N,1);
  16. h= zeros(N,1);
  17. t= zeros(N,1);
  18. τm= zeros(N,1);
  19. τn= zeros(N,1);
  20. τh= zeros(N,1);
  21. αm= zeros(N,1); #because alpha and beta are dependent of "V" and "V" is dependent of time, both of these formulas are vectors and should be put in an array. Later on in the formula of alpham you see that alpha is dependent an V[k-1], so it changes according to changes in V. The same is true for all the alpha's and beta's;
  22. βm= zeros(N,1);
  23. αn= zeros(N,1);
  24. βn= zeros(N,1);
  25. αh= zeros(N,1);
  26. βh= zeros(N,1);
  27. minfinity= zeros(N,1);
  28. ninfinity= zeros(N,1);
  29. hinfinity= zeros(N,1);
  30.  
  31. V[1]=-64.9964;    #This is the resting membrane potential?????? Initial condition; These initial conditions were one cause of the error. I put them before the zeros(N,1) arrays which caused them to be overwritten.
  32. m[1]=0.0530;      #Initial condition;
  33. n[1]=0.3177;      #Initial condition;
  34. h[1]=0.5960;      #Initial condition;
  35.  
  36. for k = 200:300
  37. Iext = 8
  38. end
  39. for k = 1000:1200
  40. Iext = 8
  41. end
  42.  
  43. for k=2:N,        #This will start the loop at N = 2. So the first value that will be calculated is K=(2 - 1) => k=1 ;
  44.  
  45.  
  46.     #because V is unknown and you have starting point V(1) you can calculate the rest;
  47.     αm[k] = 0.1 * (V[k-1]+40.) / (1. - exp(-(V[k-1]+40.)/10.));  
  48.     βm[k]  = 4. * exp(-0.0556 * (V[k-1]+65.));
  49.     αn[k] = 0.01 * (V[k-1]+55) / (1. - exp(-(V[k-1]+55.)/10.));  
  50.     βn[k] = 0.125 * exp(-(V[k-1]+65.)/80.);
  51.     αh[k] = 0.07 * exp(-0.05*(V[k-1]+65.));  
  52.     βh[k] = 1. / (1. + exp(-0.1*(V[k-1]+35.)));
  53.  
  54.     minfinity[k]  = (αm[k]) / (αm[k] + βm[k]); #This is where the error started. No matching method found;
  55.     τm[k]  = 1 / (αm[k] + βm[k]);
  56.     m[k]= (Δt*-m[k-1] + Δt*minfinity[k]) / (τm[k]) + m[k-1];
  57.  
  58.     ninfinity[k]  = (αn[k]) / (αn[k] + βn[k]);
  59.     τn[k]  = 1 / (αn[k] + βn[k]);
  60.     n[k]= (Δt*-n[k-1] + Δt*ninfinity[k]) / (τn[k]) + n[k-1];
  61.  
  62.     hinfinity[k]  = (αh[k]) / (αh[k] + βh[k]);
  63.     τh[k]  = 1 / (αh[k] + βh[k]);
  64.     h[k]= (Δt*-h[k-1] + Δt*hinfinity[k]) / (τh[k]) + h[k-1];
  65.  
  66.     V[k]= (Δt/C)*(gnamax*m[k-1]^3*h[k-1]*(Ena - V[k-1]) + gkmax*n[k-1]^4*(Ek - V[k-1]) + gl*(El - V[k-1]) + Iext[k]) + V[k-1]; # This is the hodgkin & huxley model for the generation of action potentials
  67.  
  68. end  
  69.  
  70. max = (N-1) * Δt;          # Value corresponding to the maximal integration step;
  71. t   = 0:Δt:max;            # Init of an array of N elements, with increasing values (i.e. horizontal coordinate);
  72.  
  73. fig = figure("Numerical method",figsize=(12,6));    # Create a new figure, with desired size;
  74. plot(V, Iext, "r-", label="membrane potential");             # Plot in the current figure, f(x) - the mumerical solution;
  75. ax =gca();                                  # Get a "handle" on the current axes;
  76. #ax[:set_xlim]((0,200));                      # For axes "ax" set the horizontal limits;
  77. #ax[:set_ylim]((-80,60));                     # For axes "ax" set the vertical limits;
  78. #grid("on");                                  # "Grid" on;
  79. xlabel("time (ms)");# Label of the horizontal axis
  80. ylabel("mV");                          # Label of the vertical axis
  81. title("Action Potential after paired pulse protocol");        # Label of the title, at the top of the figure
  82. #legend(borderaxespad=0.5);                     # Add a legend to the current ax
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement