Professional Documents
Culture Documents
Homework Problem 1 - Linear System of Equations
Homework Problem 1 - Linear System of Equations
clc;close all;
% what is the value of int_0^5 xe^(-x/3)dx
% using adaptive quadrature
quadInt=integral(@(x) x.*exp(-x./3),0,5);
% using trapezoidal rule
x=linspace(0,5,100);
y=x.*exp(-x./3);
trapzInt=trapz(x,y);
figure;plot(x,y,'.-');
% compute difference with -24e^(-5/3)+9
quadError=quadInt-(-24*exp(-5/3)+9);
trapzError=trapzInt-(-24*exp(-5/3)+9);
%display results
disp(['quadInt=' num2str(quadInt) ', trapzInt='
num2str(trapzInt)]);
disp(['quadError' num2str(quadError) ', trapzError='
num2str(trapzError)]);
Problem 3 – Inverse
A=[1,2;3,4];
invA=inv(A)
I=A*invA
function dydt=HHode(t,x)
% Constants
C = 1 ;
GK = 36 ;
GNa = 120 ;
GL = 0.3 ;
EK = -72 ;
ENa = 55 ;
EL = -49.4 ;
%Input Setup
n=x(1);
m=x(2);
h=x(3);
V=x(4);
% ODE
dndt=(1-n)*alphan(V)-n*betan(V);
dmdt=(1-m)*alpham(V)-m*betam(V);
dhdt=(1-h)*alphah(V)-h*betah(V);
dVdt=-1/C*(GK*n^4*(V-EK)+GNa*m^3*h*(V-ENa)+GL*(V-
EL)); %K.Webb: fix negative sign mistake
% Derivative Setup
dydt=[dndt;dmdt;dhdt;dVdt];
end
This is the solver
% a. Download the HH.zip file from the class website and unzip its
contents into your homework folder
% This zip folder contains 6 m-files: alphah.m, alpham.m,
alphan.m, betah.m, betam.m, betan.m
% These functions return the voltagedependent opening ? (V ) )
and closing ( ? (V ) ) rate constants
% for the h, m, and n ?( V ) gates: ? ( V )
%Figure formatting
xlabel('t [ms]');ylabel('Transmembrane Voltage
[mV]');title('Threshold Behavior');