Dear r-users,

I would like to convert my Matlab code to R-code, however it dies not work as expected.  Hope somebody can help me to match Matlab and r codes.

R code:

rr <- function(r,cxn)
{
tol <- 1E-4;

for(i in 1:n)
{
t1 <- (1+(i-1)*r)*log((1+(i-1)*r))
t2 <- (i-1)*(1-r)*log(1-r)
rri <- ((t1+t2)/i*log(i))-cxn
rr <- rri > tol
}
round(rr,4)
}
rr1 <- rr(0.5,0.0242) ; rr1


Matlab code:

function F = cxncnr(r)
n = 4;
% terms
t1 = (1+(n-1)*r)*log((1+(n-1)*r));
t2 = (n-1)*(1-r)*log(1-r);

%f = term - cxn
f = (t1+t2)/(n*log(n)) - 0.05011007

F = [f];
% r0 = [0.5] ; r = fsolve(@cxncnr,r0)

Thank you so much for any help given.
	[[alternative HTML version deleted]]

