VPL doesn't calculate cube root - robotics-studio

I was trying to calculate cube root using VPL:
https://www.dropbox.com/s/vjng6fjf081ovkq/shot_140214_212725.png
What I'm doing is setting the value to the power of 1/3
https://www.dropbox.com/s/4f8eqep8rm3jpw0/shot_140214_212742.png
And as a result it gives me 1 all the time.
Where the problem could be?
Thank you.

I bet 1/3 is getting truncated to 0, because the numerator and denominator are both integers.
Any number raised to the 0 power gives 1.
If you use 1.0/3.0 instead, it might work.

Related

unity Mathf.PerlinNoise not between 0 and 1

Does anybody know why this:
Debug.Log(Mathf.PerlinNoise(190911.45f, 2290937.40f));
gives me: 1.044323 It should have been between 0 and 1 isn't it?
And if it can get bigger than 1 can it get smaller than 0? I'm making a map with sprites and everything works :) except that i get empty spaces if the value is bigger than 1.
I use a random seed, that's why the numbers are so big, if you wondering.
I hope someone can help me out, Thanks :)
From the Unity Documentation,
Note: It is possible for the return value to slightly exceed 1.0f. You may need to clamp the return value if the 0.0 to 1.0 range is important to you.
So you need to use float normalized = Mathf.Clamp(Mathf.PerlinNoise(190911.45f, 2290937.40f),0,1f)
Where second argument is minimum value while third argument is maximum value.

Sum of fractions of 1 not exactly equally 1

I'm creating a 3D matrix(lat,long,landuse)and trying to calculate the fraction of the landuse for each matrix cell:
One example cell could produce a vector specified by:
fractions=landuse/total_number_of_landuse;
I have to do this for multiple cells and when I do this and sum up the fractions, some are 1 and some are 1.0000.
I know this is due to the floating point "problem".
I have to use these data for a C++-Modell which is checking the sum also and then throws me an error for some of the cells (those which summs up to 1.0000).
I also tried calculating these as double or single.
Any idea how I can make them sum up to 1?
Thanks, Philipp

Does GLPK have any option for making a small fractional to 0

I am using GLPK for solving a minimization linear programming problem in octave. its giving me some variable values like 0.0000000000277 or 0.999999999999. I want to get that 0.0000000000277 as 0 and that 0.999999999999 as 1. Does GLPK has any option for doing this? Any help will be really appreciated.
GLPK has an option called Solution Rounding which you can set to round off tiny values 0. Look for Solution Rounding among these options in GLPK.
However, for other values you will have to do a bit of post-processing by writing some code.
If 0.9 < x < 1.1, set x = 1 etc.

How to divide an absolute value of a vector in MATLAB

I want to find a vector operation such that every positive element becomes 1 and negative element becomes -1 and 0 remains 0. The first idea come to my mind is to use the following code,
a=[0.0023 0 -0.0011];
b=a./abs(a);
However, this fails to keep the 0 element in the original vector, which gives an NaN instead. How to realize this in Matlab without using a for loop? Thanks.
Use the sign function:
b=sign(a)

Adding 1 to very small numbers

I have a question about adding the number 1 to very small numbers. Right now, I am trying to plot a circular arc in the complex plane centered around the real number 1. My code looks like:
arc = 1 + rho .* exp(1i.*theta);
The value rho is a very small number, and theta runs from 0 to pi, so whenever 1 is added to the real part of arc, MATLAB seems to just round it to 1, so when I type in plot(real(arc),imag(arc)), all I see is a spike instead of a semicircle around 1. Does anyone know how to remedy this so that MATLAB will not round 1 + real(arc) to 1, and instead conserve the precision?
Thanks
rho=1e-6; theta=0:pi/100:pi; arc=1+rho*exp(1i.*theta); plot(arc); figure(); plot(arc-1);
Shows, that the problem is in plot, not in loss of precision. After rho<1e-13 there will be expected trouble with precision.
The two other possible misconceptions:
- doubles have finite precision. 16 decimal digits or 1+2^-52 is the limit with doubles.
- format short vs. format long -- matlab shows by default only 6 or 7 digits
It also happens to be that 6-7 digits is the limit of a 32-bit float, which could explain also that perhaps the plot function in Octave 3.4.3 is also implemented with floats.
Left: 1+1e-6*exp, Right: (1+1e-6*exp)-1
There is a builtin solution for exactly this probem:
exp1m()
log1p()
explicitly:
log(arc)=log1p(rho*exp(1i*theta))
to get what you need.
Of course you need to work in log space to represent this precision, but this is the typical way this is done.
In double precision floating point representations, the smallest number strictly greater than 1 that can be represented is 1 + 2^-52.
This is a limitation imposed by the way non-integer numbers are represented on most machines that can be avoided in software, but not easily. See this question about approaches for MATLAB.