¿Por qué esta función de matlab no se divide?

The function below returns a value for mu that is always equal to "result" instead of the result of the division. Why am I missing for division to work properly?

 for k = 0:10
     result = func1(.95,k);
     plusone = func1(.95,(k+1));
     fprintf('plusone = %f  result = %f\n', plusone, result);
     mu = double(plusone)/double(result);
     fprintf('mu = %f\n', mu);
 end

The code for func, if it helps, is:

 function result = func1(c, k)

 exp = 2^k;

 result = c^exp;

preguntado el 01 de febrero de 12 a las 22:02

1 Respuestas

No hay error. mu should always be equal to result porque

plusone = c^(2^(k+1)) 
        = c^(2*(2^k))
        = (c^(2^k))^2
        = result^2

result^2/result = result 

Respondido 02 Feb 12, 02:02

Unbelievable that I missed that. Thanks - mathjacks

Easy to miss error, @flapjackery. Please consider accepting the answer if it solved your issue. Cheers. - foglerit

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.