- #1
shalehound117
- 3
- 0
I'm a novice at MATLAB so I apologize if this is a dumb question: I need to find the sum of A, B and C given X, Y and Z, where ln(A)=X, ln(B)=Y etc. However, the values A, B and C are so small that when I try to use 'exp' the result is rounded to zero. This is a problem because later in my code I divide sum(A,B & C) by a number, take the log of the result and multiply this by another number as part of a loglikelihood equation. Obviously, since you cannot take the log of 0 this rounding poses a problem for my code. this part of the code is trying to find the binomial coefficient, and I can do the task with nchoosek and vpi but it slows down the code to the point that it is unusable(I'm plugging the code into fminsearch to optimize parameters, and the search takes days or cuts itself off after a time). I've tried just adding logs of numbers and subtracting the same amount later so that exp doesn't get tripped up, but I'm now faced with a situation where that doesn't work.
v=(X+Y)+z;
g=exp(v); %This is where the numbers get rounded to zero
D=sum(g);
gg=log(D); %log(0) gets turned to -Inf, cause the code to not work.
Any advice would be appreciated.
v=(X+Y)+z;
g=exp(v); %This is where the numbers get rounded to zero
D=sum(g);
gg=log(D); %log(0) gets turned to -Inf, cause the code to not work.
Any advice would be appreciated.