% This program is the first simulation. It just uses one neuron and simulate the three solution % of Differiantial Equation viz. Exact Solution, Runge Kutta and Foward Euler % Here are few of the aprameters which can be set by the user. These parameters are I=1.001; % I as input current. deltaT=0.1; % deltaT as the time interval . alpha=1; % alpha as the rate. tKnot=1; % tKnot as the initial time. uExactSolution(tKnot)=0; % uExactSolution as the membrane potential for exact solution. uRungeKutta(tKnot)=0; % uExactSolution as the membrane potential for Runge Kutta solution. uFowardEuler(tKnot)=0; % uExactSolution as the membrane potential for Foward Euler solution. j=2; for i=2:300 % Here the main loop begins and the potential is calculated for 300 time steps. uExactSolution(i)=((I/alpha)+(uExactSolution(tKnot)-(I/alpha))*(exp(-1*alpha*j*deltaT))); k1=((-1)*alpha*uRungeKutta(i-1)+(I)); k2=((-1)*alpha*(uRungeKutta(i-1)+(0.5*k1*deltaT))+(I)); k3=((-1)*alpha*(uRungeKutta(i-1)+(0.5*k2*deltaT))+(I)); k4=((-1)*alpha*(uRungeKutta(i-1)+(k3*deltaT))+(I)); uRungeKutta(i)=(uRungeKutta(i-1)+((deltaT/6)*(k1+2*k2+2*k3+k4))); uFowardEuler(i)=((uFowardEuler(i-1))+(deltaT*(((-1)*(alpha)*(uFowardEuler(i-1)))+(I)))); if(uExactSolution(i)>=1) uExactSolution(i)=0; j=1; end if(uRungeKutta(i)>=1) uRungeKutta(i)=0; end if(uFowardEuler(i)>=1) uFowardEuler(i)=0; end j=j+1; end % After calculating the complete solution the graphs are plotte for all three types of differential solution methods figure; subplot(3,1,1); plot(uExactSolution); title('Exact Solution'); xlabel('Time'); ylabel('Membrane Potential'); %figure; subplot(3,1,2); plot(uRungeKutta); title('Runge Kutta'); xlabel('Time'); ylabel('Membrane Potential'); %figure; subplot(3,1,3); plot(uFowardEuler); title('Foward Euler'); xlabel('Time'); ylabel('Membrane Potential');