0
Can someone please give me a hand? I’m trying to make a program on Octave and it’s giving me the following mistake:
max recursion Depth exceeded
error Caled from
Size at line 3 column 3
spending at line 2 column 5
First I implemented a function used to determine the expenditure of a vehicle, with a consumption c (in liters/100km) when travelling a given distance, dab (given in km), between two cities with altitudes ha and Hb (measured in meters).
function gc = gasto(ha,hb,dab,c)
if dab == 0
gc = 0;
else
gc = (c/100) * dab * (1+ 100*(hb-ha)/(1000*dab))^2;
end;
end
Then I implemented a function, expended, to transform a distance matrix, indicated by the Graph parameter, into an expense matrix, C, using the worn function, applicable to non-zero distances.
function G = gastos(Grafo,Altitudes,consumo)
n = size(Grafo,1);
G = zeros(n,n);
for i = 1 : n
for j = 1 : n
if Grafo(i,j) == 0;
G(i,j) = Inf;
else
G(i,j) = gasto(Altitudes(i),Altitudes(j),Grafo(i,j),consumo);
end;
end;
end
i used Graph = [0.102,89,0,136; 102,0,157,172,39; 89,157,0,58,0; 0,172,58,0,95; 136,39,0,95,0] Altitudes = [100, 160, 85, 90, 130] consumption = 6.5 and when calling the function expended(Graph, Altitudes, consumption) gave me this error , but I did not notice why?
someone can tell me why this mistake is coming up?
Okay, I’ve done it.
– user99237
@aluno20000, I can’t reproduce your error! And I still think you have data entry problems. Vc can reproduce the error with this or another [mcve]?
– Guto
I didn’t understand the question. I already put the code I used on top, what else am I supposed to do? You used Octave?
– user99237
@aluno20000, yes, I used Octave. Can you reproduce this error with another example? See [mcve] for an idea. Example, if you don’t do the functions and write the whole code at once (simple as it’s just copies and paste) you have the error?
– Guto
If delete: Function gc = spent(ha,Hb,dab,c) and Function G = spent(Graph,Altitudes,consumption) I get the error: invalid use of script c: spent users. m in index Expression, which does not surprise me because there are no functions in the code... I had never seen this error before
– user99237
@aluno20000, I gave an option to have a [mcve], but you may have other ideas! : D Debugging is an important and difficult part of programming. New code will be welcome. Also, see that I recommended writing the whole code again, without the use of functions. Only deleting function statements should, a priori, give problems yes.
– Guto
Thanks for the help, but then why did you recommend deleting : Function gc = spent(ha,Hb,dab,c) and Function G = spent(Graph,Altitudes,consumption), if you knew the code would not work?
– user99237