How to code and solve ODE equations many variables?
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi there,
I am new to MATLAB so i'm doing a few tutorials but they don't have memos, so any help would be appreciated! heres the required and what I've done so far:
Write an ODE file to return the following derivatives
dndt= 1− n* αn(V) − n*βn(V)
dmdt=(1 − m)*αm(V) − m*βm(V)
dhdt =(1 − h)*αh(V) − h*βh(V)
dvdt=−(1/C)* (Gk*n^4(V− Ek)+ Gna*m^3*h*(V − Ena )+ Gl(V − El ))
and the following constants ( C is membrane capacitance, G are the conductances and E are the reversal potentials of the potassium ( K ), sodium ( Na ), and leak ( L ) channels):
C = 1
Gk = 36
Gna = 120
Gl = 0.3
Ek =−72
Ena = 55
El =−49.4
and αn(V),βn(V),αm(V),βm(V),αh(V)and βh(V) are all functions whose code have been given.
Write a script called HH.m which will solve this system of ODEs and plot the transmembrane voltage. First, we’ll run the system to steady state. Run the simulation for 20ms (the timescale of the equations is ms) with initial values: n = 0.5; m = 0.5;h = 0.5;V =−60 (ode45)
seems simple enough.... my code is as follows:
function rk=chem(t,V)
C=1 Gk=36 Gna=120 Gl=0.3 Ek=-72 Ena=55 El=-49.4 V=zeros(4,1)
V(1)= (1-n).*'alphan' -n.*'betan'
V(2)= (1-m).*'alpham'-m.*'betam' V(3)= (1-h).*'alphah'-h.*'betah'
V(4)= -(1/C)*(Gk*n^4*(V-Ek)+Gna*m^3*h*(V-Ena)+Gl*(V-El)) rk=[V(1);V(2);V(3);V(4)] end
timerange=[0 20]
initialvalues=[0.5 0.5 0.5 -60]
[t,y]=ode45(@chem,timerange,initialvalues)
plot(t,y(:,1))
but the damn thing keeps telling me that t is undefined! please help, I know it looks long but any help would be appreciated.
0 comentarios
Respuestas (2)
Star Strider
el 11 de Mayo de 2014
‘but the damn thing keeps telling me that t is undefined! please help, I know it looks long but any help would be appreciated.’
Please don’t be angry with it! The ODE solvers require the ODE function to return [t,y]. Change your function line from:
function rk=chem(t,V)
to:
function [t,V]=chem(t,V)
and if there are no other problems, your code should run. You might want to define alphan, betan, and n before you run it.
Also, put semicolons (;) at the end of your lines in chem. Otherwise, it will output the result of every line in every iteration to the Command Window.
3 comentarios
Star Strider
el 11 de Mayo de 2014
I am now totally lost! I have no idea what you are doing. I can tell by inspection though that MATLAB is going to have serious problems with your code.
Please see the documentation on ode45 and the other solvers for details on how to write your ODE function. Then see ‘The Hodgkin Huxley Model’. They also implement it in MATLAB.
Ver también
Categorías
Más información sobre Ordinary Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!