0

I have run the following code in the Octave (Octave-6.2.0 (Local) (GUI)) and the output is shown. I have made an error intentionally, but when I fix it, it does not recognize it. Even when I have copied and pasted the following code which does not have an error it shows the same error message. By the way, it can be solved if I close Octave and open it again.

P=[1200 3000 4200 5500];
I=[10000];
function result = irrm(P,I)
  result = 100*irr(P,I)
end
irrm(P,I);

Output:

>> rr

result = 11.798

The code with an error is:

P=[1200 3000 4200 5500];
I=[10000];
function result = irr(P,I)
  result = 100*irr(P,I)
end
irrm(P,I);

The output of the code with an error is:

>> rr

error: max_recursion_depth exceeded
error: called from
    irr
    irr at line 5 column 10
    irrm at line 5 column 10
    rr at line 7 column 1
Ali
  • 1
  • The code at the top references `irr`, which you don't define. The other code defines a function `irr` that calls itself indefinitely, it is a recursive function without an exit condition. Both these things are pretty obvious. What do you expect to learn from your post here? – Cris Luengo May 07 '21 at 19:55
  • irr is already defined by the financial package. – Ali May 07 '21 at 23:19
  • Then what is the problem? "If I try to run code with an error it doesn't work." That was obvious. Your first bit of code works, no? I don't understand what you are asking... – Cris Luengo May 07 '21 at 23:22
  • Oh, once you've run the second bit of code, you've defined a new function `irr` that hides the one you're actually trying to call. Running the first bit of code now uses this new, buggy function that you wrote, rather than the one in the financial package. `clear irr` will delete that function from memory, making the original one available again. – Cris Luengo May 07 '21 at 23:25
  • yes it works, but when I have run the second code it shows an error. Now, I have replaced the one with an error with the first one in the same session, but it shows the same error like I am running the one with an error. – Ali May 07 '21 at 23:25

0 Answers0