Why is there an error when I call my function?
1 次查看(过去 30 天)
显示 更早的评论
if true
function dzdt = hodgefun(t,z)
Vna = 115; Vk = -12; V = 10.6;
g_na = 120; g_K = 36; g_L = 0.3;
Cm = 1; i = 9;
Vm=z(1);
m=z(2);
n=z(3);
h=z(3);
Er = -70;
E = [-50 -55];
Vm = E - Er;
A_n = (0.01.*(Vm+10))./(exp(((Vm+10)./10)-1));
B_n = 0.125.*exp(Vm./80);
A_m = (0.1.*(Vm+25))./(exp(((Vm+25)./10)-1));
B_m = 4.*exp(Vm./18);
A_h = 0.07.*exp(Vm./20);
B_h = 1./(exp(((Vm+30)./10)+1));
dVmdt= [i - ((g_K.*(n.^4)).*(Vm - Vk)) - ((g_na.*(m.^3).*h).*(Vm - Vna)) - (g_L.*(Vm - V_L))]./Cm;
dmdt= (A_m.*Vm.*(1-m)) - (B_m.*Vm.*m)
dndt= (A_n.*Vm.*(1-n)) - (B_n.*Vm.*n)
dhdt= (A_h.*Vm.*(1-h)) - (B_h.*Vm.*h)
dzdt=[dVmdt; dmdt; dndt; dhdt]
end of function this was my main function:
if true
initial_conditions= [0,9]
tspan=[0 100];
[t,z] = ode45 ('part1',tspan,initial_conditions)
end
but i get this error and I don't know why:
Index exceeds matrix dimensions.
Error in part1 (line 8) m=z(2);
Error in odearguments (line 90) f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115) odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin); end
1 个评论
Star Strider
2017-4-12
‘i get this error and I don't know why’
Neither do we, because you did not post the code to ‘part1’.
回答(1 个)
Rollin Baker
2017-4-14
You are seeing this error because you are trying to access 'z(2)', but 'z' only contains one element. It seems that you are expecting the 'ode45' function to return multiple solutions.
Since we don't have access to 'part1', it would be hard for anyone to figure out why this is happening, but I would begin by confirming that the solutions from 'ode45' are what you expect. This should be a good starting point to reach your solution.
I hope this was helpful. Good luck on your project!
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!