From 1175dc3ab98aa738c2469c14620e44e6f8f8601c Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Mon, 23 Jan 2017 13:30:51 +0100 Subject: [PATCH] added lif project --- projects/project_lif/Makefile | 10 ++ projects/project_lif/lif.tex | 160 ++++++++++++++++++ projects/project_lif/solution/lif.m | 116 +++++++++++++ projects/project_lif/solution/lifspikes.m | 14 ++ .../project_lif/solution/passivemembrane.m | 8 + 5 files changed, 308 insertions(+) create mode 100644 projects/project_lif/Makefile create mode 100644 projects/project_lif/lif.tex create mode 100644 projects/project_lif/solution/lif.m create mode 100644 projects/project_lif/solution/lifspikes.m create mode 100644 projects/project_lif/solution/passivemembrane.m diff --git a/projects/project_lif/Makefile b/projects/project_lif/Makefile new file mode 100644 index 0000000..6422eb4 --- /dev/null +++ b/projects/project_lif/Makefile @@ -0,0 +1,10 @@ +latex: + pdflatex *.tex > /dev/null + pdflatex *.tex > /dev/null + +clean: + rm -rf *.log *.aux *.zip *.out auto + rm -f `basename *.tex .tex`.pdf + +zip: latex + zip `basename *.tex .tex`.zip *.pdf *.dat *.mat *.m diff --git a/projects/project_lif/lif.tex b/projects/project_lif/lif.tex new file mode 100644 index 0000000..e42d352 --- /dev/null +++ b/projects/project_lif/lif.tex @@ -0,0 +1,160 @@ +\documentclass[addpoints,11pt]{exam} +\usepackage{url} +\usepackage{color} +\usepackage{hyperref} + +\pagestyle{headandfoot} +\runningheadrule +\firstpageheadrule +\firstpageheader{Scientific Computing}{Project Assignment}{11/05/2014 + -- 11/06/2014} +%\runningheader{Homework 01}{Page \thepage\ of \numpages}{23. October 2014} +\firstpagefooter{}{}{} +\runningfooter{}{}{} +\pointsinmargin +\bracketedpoints + +%%%%% listings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\usepackage{listings} +\lstset{ + basicstyle=\ttfamily, + numbers=left, + showstringspaces=false, + language=Matlab, + breaklines=true, + breakautoindent=true, + columns=flexible, + frame=single, +% captionpos=t, + xleftmargin=2em, + xrightmargin=1em, +% aboveskip=11pt, + %title=\lstname, +% title={\protect\filename@parse{\lstname}\protect\filename@base.\protect\filename@ext} + } + + +%\printanswers +%\shadedsolutions + + +\begin{document} +%%%%%%%%%%%%%%%%%%%%% Submission instructions %%%%%%%%%%%%%%%%%%%%%%%%% +\sffamily +% \begin{flushright} +% \gradetable[h][questions] +% \end{flushright} + +\begin{center} + \input{../disclaimer.tex} +\end{center} + +%%%%%%%%%%%%%% Questions %%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{questions} + \question The temporal evolution of the membrane voltage $V(t)$ of a + passive neuron is described by the membrane equation + \begin{equation} + \label{passivemembrane} + \tau \frac{dV}{dt} = -V + E + \end{equation} + where $\tau=10$\,ms is the membrane time constant and $E(t)$ is the + reversal potential that also depends on time $t$. + + Such a differential equation can be numerically solved with the Euler method. + For this the time is discretized by a time step $\Delta t=0.1$\,ms. + The $i$-th time point is then at time $t_i = i \cdot \Delta t$. + In matlab we get the time points $t_i$ simply by + \begin{lstlisting} +dt = 0.1; +tmax = 100.0; +time = [0.0:dt:tmax]; % t_i + \end{lstlisting} + When the membrane potential at time $t_0 = 0$ is $V_0$, the so + called ``initial condition'', then we can iteratively compute the + membrane potentials $V_i$ for successive time points $t_i$ according to + \begin{equation} + \label{euler} + V_{i+1} = V_i + (-V_i + E_i) \frac{\Delta t}{\tau} + \end{equation} + + \begin{parts} + \part Write a function that computes the time course of the + membrane potential of the passive membrane. The function gets as + input arguments the initial condition $V_0$, the vector with the + time course of $E(t)$, the value of the membrane time-constant + $\tau$, and the time step $\Delta t$. + + \part In order to test your function set $V_0=1$\,mV and $E(t)=0$ + and compute $V(t)$ for $t_{max}=50$\,ms. Plot $V(t)$ and compare it to + the expected result of $V(t) = \exp(-t/\tau)$. + + Why is $V=0$ the resting potential of this neuron? + + \part Response of the passive membrane to a step input. + + Set $V_0=0$. Construct a vector for the input $E(t)$ such that + $E(t)=0$ for $t<20$\,ms and $t>70$\,ms and $E(t)=10$\,mV for + $20$\,ms $100.0); + if length(spikes) > 2 + rates(k) = 1000.0*(length(spikes)-1)/(spikes(end)-spikes(1)); + else + rates(k) = 0.0; + end + end + plot(freqs, rates); + hold on; +end +hold off; \ No newline at end of file diff --git a/projects/project_lif/solution/lifspikes.m b/projects/project_lif/solution/lifspikes.m new file mode 100644 index 0000000..328b927 --- /dev/null +++ b/projects/project_lif/solution/lifspikes.m @@ -0,0 +1,14 @@ +function [spikes, voltage] = lifspikes(V0, E, tau, dt) +voltage = zeros(length(E), 1); +V = V0; +thresh = 1.0; +spikes = []; +for k = 1:length(E) + voltage(k) = V; + if V > thresh + spikes = [spikes; k*dt]; + V = 0.0; + end + V = V + (-V+E(k))*dt/tau; +end +end diff --git a/projects/project_lif/solution/passivemembrane.m b/projects/project_lif/solution/passivemembrane.m new file mode 100644 index 0000000..b6c2a2d --- /dev/null +++ b/projects/project_lif/solution/passivemembrane.m @@ -0,0 +1,8 @@ +function voltage = passivemembrane(V0, E, tau, dt) +voltage = zeros(length(E), 1); +V = V0; +for k = 1:length(E) + voltage(k) = V; + V = V + (-V+E(k))*dt/tau; +end +end