Command "indnv" cannot find index of a value

I find that when b is large in indnv(a, b), it returns a missing value, even if I know a is in vector b.

Here is an example that is not working for me:

z = 1000;
b = seqa(-1/z,1/z,z+2);
a = { 0.049, 0.999 };
c = indnv(a,b);
print c;
.
.

Help!

3 Answers



0



accepted

The problem here is not the size of b, but rounding errors inherent in floating point arithmetic. If you print all the digits in b you will see the difference.

format /rd 16,16;
print b;

You will see that that second to last element of b is:

0.9990000000000008

and if you print 0.999, it will be:

0.9990000000000000

This is not a problem particular to GAUSS, it is a limitation of the double precision values that computers use. You can avoid this problem by making your original sequence from -1 to 1000 and the dividing by 1000 like this:

z = 1000;
b = seqa(-1, 1, z+2)./z;
a = { 0.049, 0.999 };
c = indnv(a, b);
print c;

You should see:

51.0000000000000000
1001.0000000000000000

I think this should work for you, because it does not require you to know any more information at the time of the creation of b.

aptech

1,773


0



When you say that b is large, do you mean that b has many elements, or that the individual values in b are large?

Do these examples work for you?
Example 1: Many elements in b

b = rndn(1e7, 1);               
idx = { 9, 41, 10009, 9999746 };
a = b[idx];
out = indnv(a,b);
print out; 
 9.0000000 
 41.000000 
 10009.000 
 9999746.0 

Example 2: Large values in b
Continuing with the data from above:

b = b.*1e90;
a = b[idx];
out2 = indnv(a, b);
print out2;
 9.0000000 
 41.000000 
 10009.000 
 9999746.0 

Both of these work for me using GAUSS version 13. Let me know if these work for you and/or a more specific description of your problem.

aptech

1,773


0



I mean b has many elements. I wonder why the following does not work:

z=1000;
b=seqa(-1/z,1/z,z+2);
a=0.999;
indnv(0.999,b);

Your Answer

3 Answers

0
accepted

The problem here is not the size of b, but rounding errors inherent in floating point arithmetic. If you print all the digits in b you will see the difference.

format /rd 16,16;
print b;

You will see that that second to last element of b is:

0.9990000000000008

and if you print 0.999, it will be:

0.9990000000000000

This is not a problem particular to GAUSS, it is a limitation of the double precision values that computers use. You can avoid this problem by making your original sequence from -1 to 1000 and the dividing by 1000 like this:

z = 1000;
b = seqa(-1, 1, z+2)./z;
a = { 0.049, 0.999 };
c = indnv(a, b);
print c;

You should see:

51.0000000000000000
1001.0000000000000000

I think this should work for you, because it does not require you to know any more information at the time of the creation of b.

0

When you say that b is large, do you mean that b has many elements, or that the individual values in b are large?

Do these examples work for you?
Example 1: Many elements in b

b = rndn(1e7, 1);               
idx = { 9, 41, 10009, 9999746 };
a = b[idx];
out = indnv(a,b);
print out; 
 9.0000000 
 41.000000 
 10009.000 
 9999746.0 

Example 2: Large values in b
Continuing with the data from above:

b = b.*1e90;
a = b[idx];
out2 = indnv(a, b);
print out2;
 9.0000000 
 41.000000 
 10009.000 
 9999746.0 

Both of these work for me using GAUSS version 13. Let me know if these work for you and/or a more specific description of your problem.

0

I mean b has many elements. I wonder why the following does not work:

z=1000;
b=seqa(-1/z,1/z,z+2);
a=0.999;
indnv(0.999,b);

You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.