Hey guys,
I have a IRC5 running RW6.15.01 and I wrote a function for caculating the cubic root of any input value. The function is basically working but for some input values the function will repeat the while loop infinitely and will not return a result. My assumption is, that input values <1 will cause this problem. The thing is that the same function written in Matlab or Scilab is working with any value.
Code
LOCAL FUNC num Diff(num n,num mid)
IF (n=0) THEN
RETURN 0;
ELSEIF (n>Pow(mid,3)) THEN
RETURN (n-Pow(mid,3));
ELSE
RETURN (Pow(mid,3)-n);
ENDIF
ENDFUNC
LOCAL FUNC num CubicRoot(num n)
VAR num nError;
VAR num nStart;
VAR num nEnd;
VAR num nMid;
CONST num nE:=0.001;
nStart:=0;
nEnd:=n;
WHILE TRUE DO
nMid:=(nStart+nEnd)/2;
nError:=Diff(n,nMid);
IF (nError<=nE) THEN
RETURN nMid;
ENDIF
IF (Pow(nMid,3)>n) THEN
nEnd:=nMid;
ELSE
nStart:=nMid;
ENDIF
ENDWHILE
ENDFUNC
Display More
Maybe somebody of you has an idea on how to calculate the cubic root in RAPD. Or maybe somebody did this before. I appreciate any help!