I am developing a project in plain C++ using VS2010, I need to calculate the arc cosine of a real value (can be out of -1;1 range, so need to deal with complex numbers) and compare it with a double to see whether or not a threshold is satisfied
To make things clear, I need to convert this code (which works in matlab)
% dotprods is a vector of real values
tempvar=acos(dotprods); % inverse cosine, some of these values are complex
[vals,indx] = sort(tempvar); % Take inverse cosine and sort results
% value compare
if (vals(1) < threshold * secondvalue)
% condition is TRUE
% condition is FALSE
Unfortunately the acos function does not work with complex numbers.
I tried to arrange things this way:
for(int j...) // cycle values of the vector
// dotprods is a ublas double vector with real values
complex<double> c(0,1); // i
complex<double> one(1,0); // 1
You have integer division here. The result of 1 / 2 is 0. Use 0.5 if you want a floating point number. Better yet use the function sqrt (square-root).
Also, instead of using pow(x, 2) just use x * x. It's faster if the compiler is not able to do this for you (I doubt it is).
June 9th, 2010, 06:32 AM
Re: Big Math problem
Thank you D_Drmrr, you solved my problem. I did not notice that, you was absolutely right :D