[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
NaN error
From: |
Los Griegos Engineering |
Subject: |
NaN error |
Date: |
Tue, 11 Jan 2011 11:35:58 -0600 |
Hello all,
I came across the 196 algorithm at:
http://mathworld.wolfram.com/196-Algorithm.html
I decided to code a version of it, and it works... until I increase the
iterations past a limit. I think the error is in the memory, but I'm
just not sure where the error is.
function [ a ] = rev (a,iter)
for k=1:iter
a=num2str(a);
b=[];
for i=length(a):-1:1
j=length(a)-i+1;
b(j)=a(i);
endfor
b=str2double(b);
a=str2double(a);
a=b+a;
endfor
endfunction
The results I get are:
octave-3.2.3> rev(123,1)
ans = 444
octave-3.2.3> rev(123,10)
ans = 1354353
octave-3.2.3> rev(123,11)
ans = NaN
octave-3.2.3> rev(12,11)
ans = 175857
octave-3.2.3> rev(12,14)
ans = NaN
octave-3.2.3>
Is the error due to the memory address of the character array?
GNU Octave, version 3.2.3
Octave was configured for "i486-pc-linux-gnu".
Regards,
Mon
- NaN error,
Los Griegos Engineering <=