- 3
- 0
I have a piece of code which near its end needs to do the following task: Given a vector V=(log(A),log(B),log(C)) that has been previously generated[I've used 'log' as opposed to ln here because the 'log' function in matlab is the natural logarithm], I need to find sum(A,B,C). NOT sum(log(A),log(B),log(C))=log(A*B*C), but sum(A,B,C). However, log(A),log(B) and log(C) are each large negative numbers (log(A)=-6126.9,log(B)=-4371.2,log(C)=-2942.1) When I use exp the results are rounded to zero. This is a problem, because the next step in the code is log(D), where D=sum(A,B,C), and log(0)=-Inf (I have a good reason for going from log to exp and back again). I can use the symbolic math toolbox to get the precision I need so that the results for using 'exp' are very small numbers instead of being rounded to 0. However, I don't know how to put this inside my code, i.e. when I type k=sym('exp(v(1,1))') in the matlab command window, it returns k=exp(v(1,1)) as opposed to the value 1.3217180682567377112866860751447*10^(-2661), which is what I get when I do k=sym('exp(-6126.9)'). How can I use sym('exp()') with a particular element of a vector so that I can put this in my code? I'm new to matlab, and if part of the problem is I'm trying to use a tool without understanding how it works, well, learning is exactly why I am at this forum. Thank you very much to anyone who has any advice.