i have different result
Mostrar comentarios más antiguos
hello;
i have a simple question, i don't knew if it setting probleme or not
i'm makin a loop to calculate some variables.
for T=[100;1000;10000];
ProbDG=1-(1/T);
DGT=-log(-log(ProbDG))
end
so i get ProbDG= [1 1 0.9999] instead of [0.9900 0.9990 0.9999] and DGT= [ Inf Inf 9.2103] instead of [ 9.21 6.91 4.60 ]
i don't understand why i have this number because in Ecxel i get the right result
Respuesta aceptada
Más respuestas (1)
Steven Lord
el 18 de Feb. de 2020
for T=[100;1000;10000]; % Original code
When you call for with a vector as its loop variable definition, it iterates over the columns of the matrix you specify (not the elements.) So T does not take on the elements of [100; 1000; 10000] in turn, instead the loop iterates once with the whole column vector as T.
ProbDG=1-(1/T); % Original code
So ProbDG is a vector such that x*[100; 1000; 10000] = 1.
T = [100; 1000; 10000]; % New code
x = 1/T;
x*T
x is not unique, three possible vectors x could be are [1/100, 0, 0], [0, 1/1000, 0], or [0, 0, 1/10000].
Since you wanted to compute the reciprocal of each element of T and subtract that result from 1, you need to use the ./ operator instead.
DGT=-log(-log(ProbDG)) % Original code
end
Because ProbDG is not what you expected, DGT will not be either.
You could receive the results you expected by either making the T vector a row vector or using the ./ operator in the definition of ProbDG. If you make T a row vector the loop body will run three times, each on a scalar value. For scalar T the expressions 1/T and 1./T work the same way. Or you could just eliminate the loop and use the ./ operator as Adam suggested.
Categorías
Más información sobre Programming en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!