Keep getting error: Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N) to change the limit. Be aware that exceeding your available stack space can crash MATLAB and/or your computer.
조회 수: 1 (최근 30일)
이전 댓글 표시
function [z, p, u] = equilibria(Ca, param);
pt = param(1); ep0 = param(2); I0 = param(3); vCaN = param(4); vPKA = param(5); Km = param(6); Kh2 = param(8); K1 = param(9); K2 = param(10); K3 = param(11); K4 = param(12); N = param(13);
Ca_rest =0.1; Ca_amp =5; gam = (Ca_rest / Kh2)^3 /(1 + (Ca_rest / Kh2)^3);
I_equ = vPKA / vCaN / gam * I0; ep_equ = K4*ep0 / (K3*I_equ + K4); [z, p, u] = equilibria(Ca_rest, param); p_init= p(:, 1); x_init= [ep_equ; I_equ]; toff= 1800; h = 1.5; tstop = toff + h*3600; Ca = Ca_rest; pt = ek; w_a= (Ca / Kh1)^4 / (1 + (Ca / Kh1)^4); v1= 10 * K1 * w_a^2; v2= K1 * w_a; w = [1.0 1.8 2.3 2.7 2.8 2.7 2.3 1.8 1.0]; S = [zeros(1,N); eye(N-1) zeros(N-1,1)]; Aa = v2 * ( -diag([0 w]) + S*diag([w 0]) ) - v1 * eye(N,1)*ones(1,N); Ba = v1 * eye(N,1);
dAa = -K1 * ( -diag([0 w]) + S*diag([w 0]) ) -20*K1*w_a * eye(N,1)*ones(1,N); ddAa= - 20*K1* eye(N,1)*ones(1,N); x0= pt*ones(N,1); %[0 0 0 0 0 0 0 0 0 pt]'; dBa= 20*K1*w_a * eye(N,1); ddBa= 20*K1* eye(N,1); A01= dAa*x0 + dBa*pt; A11= dAa; A02= ddAa*x0 + ddBa*pt;
w_a = (Ca / Kh1)^4 / (1 + (Ca / Kh1)^4) v1 = 10*K1 * w_a^2; v2 =K1*w_a; w = [1.0 1.8 2.3 2.7 2.8 2.7 2.3 1.8 1.0]; S = [zeros(1,N); eye(N-1) zeros(N-1,1)]; Aa = -v2 * ( diag([w 0]) - S*diag([w 0]) ) -v1 * eye(N,1)*ones(1,N) ; Ba = v1 * eye(N,1); ; C0 = (Ca / Kh2)^3 / (1 + (Ca / Kh2)^3) I_equ = vPKA / vCaN / C0 * I0; ep_equ = K4*ep0 / (K3*I_equ + K4);
w_d= ep_equ; D= eye(N) -[zeros(N-1,1) eye(N-1); zeros(1,N)]; L= diag(1:N); Ad = w_d*D*L;
A =Ad\ Aa; B =Ad\ Ba*pt; C = 1:N; D = Km;
sys = tf( ss(A, B, C, D) ); poly_u = [sys.num{1} 0] - K2*[0 sys.den{1}]; u_roots = roots(poly_u); idx = setdiff(1:length(u_roots), find(u_roots - real(u_roots))); u = u_roots(idx)'; z = []; p = [];
if ~isempty(u) for k = 1:length(u) pk = - (Aa - u(k)*Ad) \ Ba * pt; p = [p pk]; z = [z (1:N)*pk]; end end
댓글 수: 0
답변 (2개)
Star Strider
2016년 4월 8일
This is at least one of your problems (I didn’t go through your entire code, so you might have called it other places as well):
...
I_equ = vPKA / vCaN / gam * I0;
ep_equ = K4*ep0 / (K3*I_equ + K4);
[z, p, u] = equilibria(Ca_rest, param); % <— Please Do Not Call Your Function From Within The Function!
p_init= p(:, 1);
x_init= [ep_equ; I_equ];
...
Calling your function from within the same function will throw this error.
The solution is to re-write your code to avoid it.
See the documentation for Function Basics. You might need to use nested functions or other function constructions, in order to avoid this problem.
댓글 수: 0
Roger Stafford
2016년 4월 8일
Your code is clearly meant to be recursive. However, there is something wrong in the way it is planned. You first call "equilibria' with arguments, 'Ca' and 'param'. Without altering 'param' within 'equilibria' you again call it recursively with arguments 'Ca_rest' and 'param'. Neither of these quantities is altered therein. After that the recursive calls to 'equilibria' will continue indefinitely with the same values of 'Ca_rest' and 'param', which is the reason you reached the limit of 500. It will do no good to extend this limit, since these repetitions would continue indefinitely. You need to correct the logic of your function 'equilibria' so that the arguments it is called with will change before it is called again and in a manner that will eventually result in emerging at the top of the stack of recursive calls.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Beamforming and Direction of Arrival Estimation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!