why
distance+=Math.sqrt(Math.pow((double)wiersz_analiz owany[i],(double)2)-Math.pow((double)czyNajblizszySasiad[i],(double)2));
returns NaN
thank YOU
14 3359
why
distance+=Math.sqrt(Math.pow((double)wiersz_analiz owany[i],(double)2)-Math.pow((double)czyNajblizszySasiad[i],(double)2));
returns NaN
thank YOU
Remember the poor men's debugger System.out.println()? Apply it.
(hint: negative values don't go well for the Math.sqrt() method).
kind regards,
Jos
Correct.
make a loop and ...
System,out.println(czyNajblizszySasiad[i])
Remember the poor men's debugger System.out.println()? Apply it.
(hint: negative values don't go well for the Math.sqrt() method).
kind regards,
Jos
i did system.out.printlns and the values are correct they are 0 ,1 ,2 or 3
because test data are rows consisted of 0 1 2 or 3 values
i did system.out.printlns and the values are correct they are 0 ,1 ,2 or 3
because test data are rows consisted of 0 1 2 or 3 values
For all the operands of your expression print out all the operands and the
values of the evaluated (sub) expressions. a NaN (Not a Number) doesn't come
from nowhere.
kind regards,
Jos
-
public double liczDystans(Integer[] czyNajblizszySasiad){
-
for(int i=0;i<liczbaColumn;i++){
-
dystans+=Math.sqrt(Math.pow((double)wiersz_analizowany[i],(double)2)-Math.pow((double)czyNajblizszySasiad[i],(double)2));
-
-
System.out.println("wiersz_analizowany[i]="+wiersz_analizowany[i]);
-
System.out.println("Math.pow((double)wiersz_analizowany[i],(double)2)"+Math.pow((double)wiersz_analizowany[i],(double)2));
-
-
System.out.println("czyNajblizszySasiad[i]="+czyNajblizszySasiad[i]);
-
System.out.println("Math.pow((double)czyNajblizszySasiad[i],(double)2)"+Math.pow((double)czyNajblizszySasiad[i],(double)2));
-
-
System.out.println("dystans="+dystans);
-
}
-
return dystans;
-
}
-
System.out.println("Math.pow((double)wiersz_analiz owany[i],(double)2)"+Math.pow((double)wiersz_analizowany[i],(double)2));
and
System.out.println("Math.pow((double)czyNajblizszy Sasiad[i],(double)2)"+Math.pow((double)czyNajblizszySasiad[i],(double)2));
return a double sqrt
Math.sqrt(Math.pow((double)wiersz_analizowany[i],(double)2)-Math.pow((double)czyNajblizszySasiad[i],(double)2));
returns nan ?
it may happen that in my for loop dystans is equal to NaN but what happens if i add a double to NaN does it still return NaN ?
-
public double liczDystans(Integer[] czyNajblizszySasiad){
-
for(int i=0;i<liczbaColumn;i++){
-
dystans+=Math.sqrt(Math.pow((double)wiersz_analizowany[i],(double)2)-Math.pow((double)czyNajblizszySasiad[i],(double)2));
-
-
System.out.println("wiersz_analizowany[i]="+wiersz_analizowany[i]);
-
System.out.println("Math.pow((double)wiersz_analizowany[i],(double)2)"+Math.pow((double)wiersz_analizowany[i],(double)2));
-
-
System.out.println("czyNajblizszySasiad[i]="+czyNajblizszySasiad[i]);
-
System.out.println("Math.pow((double)czyNajblizszySasiad[i],(double)2)"+Math.pow((double)czyNajblizszySasiad[i],(double)2));
-
-
System.out.println("dystans="+dystans);
-
}
-
return dystans;
-
}
-
System.out.println("Math.pow((double)wiersz_analiz owany[i],(double)2)"+Math.pow((double)wiersz_analizowany[i],(double)2));
and
System.out.println("Math.pow((double)czyNajblizszy Sasiad[i],(double)2)"+Math.pow((double)czyNajblizszySasiad[i],(double)2));
return a double sqrt
Math.sqrt(Math.pow((double)wiersz_analizowany[i],(double)2)-Math.pow((double)czyNajblizszySasiad[i],(double)2));
returns nan ?
Print the arguments you're passing to Math.pow as well.
I'm sure you have this open while doing this.
it may happen that in my for loop dystans is equal to NaN but what happens if i add a double to NaN does it still return NaN ?
Yes, any operator yields NaN or false when at least one of the operands equals
Nan. Even NaN == NaN is false as well as NaN != NaN. It's Not a Number ;-)
kind regards,
Jos
i changed it to
dystans=Math.sqrt(Math.pow((double)wiersz_analizow any[0],(double)2)-Math.pow((double)czyNajblizszySasiad[0],(double)2)+
Math.pow((double)wiersz_analizowany[1],(double)2)-Math.pow((double)czyNajblizszySasiad[1],(double)2) +
Math.pow((double)wiersz_analizowany[2],(double)2)-Math.pow((double)czyNajblizszySasiad[2],(double)2)+
Math.pow((double)wiersz_analizowany[3],(double)2)-Math.pow((double)czyNajblizszySasiad[3],(double)2)+
Math.pow((double)wiersz_analizowany[4],(double)2)-Math.pow((double)czyNajblizszySasiad[4],(double)2)+
Math.pow((double)wiersz_analizowany[5],(double)2)-Math.pow((double)czyNajblizszySasiad[5],(double)2)+
Math.pow((double)wiersz_analizowany[6],(double)2)-Math.pow((double)czyNajblizszySasiad[6],(double)2)+
Math.pow((double)wiersz_analizowany[7],(double)2)-Math.pow((double)czyNajblizszySasiad[7],(double)2)+
Math.pow((double)wiersz_analizowany[8],(double)2)-Math.pow((double)czyNajblizszySasiad[8],(double)2)+
Math.pow((double)wiersz_analizowany[9],(double)2)-Math.pow((double)czyNajblizszySasiad[9],(double)2)+
Math.pow((double)wiersz_analizowany[10],(double)2)-Math.pow((double)czyNajblizszySasiad[10],(double)2)+
Math.pow((double)wiersz_analizowany[11],(double)2)-Math.pow((double)czyNajblizszySasiad[11],(double)2)+
Math.pow((double)wiersz_analizowany[12],(double)2)-Math.pow((double)czyNajblizszySasiad[12],(double)2)+
Math.pow((double)wiersz_analizowany[13],(double)2)-Math.pow((double)czyNajblizszySasiad[13],(double)2)+
Math.pow((double)wiersz_analizowany[14],(double)2)-Math.pow((double)czyNajblizszySasiad[14],(double)2)+
Math.pow((double)wiersz_analizowany[15],(double)2)-Math.pow((double)czyNajblizszySasiad[15],(double)2)+
Math.pow((double)wiersz_analizowany[16],(double)2)-Math.pow((double)czyNajblizszySasiad[16],(double)2)+
Math.pow((double)wiersz_analizowany[17],(double)2)-Math.pow((double)czyNajblizszySasiad[17],(double)2)+
Math.pow((double)wiersz_analizowany[18],(double)2)-Math.pow((double)czyNajblizszySasiad[18],(double)2)+
Math.pow((double)wiersz_analizowany[19],(double)2)-Math.pow((double)czyNajblizszySasiad[19],(double)2)
);
but still distance is 0.0 or NaN Math.pow returns correct numbers i checked that it's sqrt that returns NaN or 0.0 where the result should be
eg 6.2 (first row of my test data)i counted
i changed it to
dystans=Math.sqrt(Math.pow((double)wiersz_analizow any[0],(double)2)-Math.pow((double)czyNajblizszySasiad[0],(double)2)+
Math.pow((double)wiersz_analizowany[1],(double)2)-Math.pow((double)czyNajblizszySasiad[1],(double)2) +
Math.pow((double)wiersz_analizowany[2],(double)2)-Math.pow((double)czyNajblizszySasiad[2],(double)2)+
Math.pow((double)wiersz_analizowany[3],(double)2)-Math.pow((double)czyNajblizszySasiad[3],(double)2)+
Math.pow((double)wiersz_analizowany[4],(double)2)-Math.pow((double)czyNajblizszySasiad[4],(double)2)+
Math.pow((double)wiersz_analizowany[5],(double)2)-Math.pow((double)czyNajblizszySasiad[5],(double)2)+
Math.pow((double)wiersz_analizowany[6],(double)2)-Math.pow((double)czyNajblizszySasiad[6],(double)2)+
Math.pow((double)wiersz_analizowany[7],(double)2)-Math.pow((double)czyNajblizszySasiad[7],(double)2)+
Math.pow((double)wiersz_analizowany[8],(double)2)-Math.pow((double)czyNajblizszySasiad[8],(double)2)+
Math.pow((double)wiersz_analizowany[9],(double)2)-Math.pow((double)czyNajblizszySasiad[9],(double)2)+
Math.pow((double)wiersz_analizowany[10],(double)2)-Math.pow((double)czyNajblizszySasiad[10],(double)2)+
Math.pow((double)wiersz_analizowany[11],(double)2)-Math.pow((double)czyNajblizszySasiad[11],(double)2)+
Math.pow((double)wiersz_analizowany[12],(double)2)-Math.pow((double)czyNajblizszySasiad[12],(double)2)+
Math.pow((double)wiersz_analizowany[13],(double)2)-Math.pow((double)czyNajblizszySasiad[13],(double)2)+
Math.pow((double)wiersz_analizowany[14],(double)2)-Math.pow((double)czyNajblizszySasiad[14],(double)2)+
Math.pow((double)wiersz_analizowany[15],(double)2)-Math.pow((double)czyNajblizszySasiad[15],(double)2)+
Math.pow((double)wiersz_analizowany[16],(double)2)-Math.pow((double)czyNajblizszySasiad[16],(double)2)+
Math.pow((double)wiersz_analizowany[17],(double)2)-Math.pow((double)czyNajblizszySasiad[17],(double)2)+
Math.pow((double)wiersz_analizowany[18],(double)2)-Math.pow((double)czyNajblizszySasiad[18],(double)2)+
Math.pow((double)wiersz_analizowany[19],(double)2)-Math.pow((double)czyNajblizszySasiad[19],(double)2)
);
but still distance is 0.0 or NaN Math.pow returns correct numbers i checked that it's sqrt that returns NaN or 0.0 where the result should be
eg 6.2 (first row of my test data)i counted
Basically you're doing: -
Math.sqrt(Math.pow(x, 2)-Math.pow(y, 2))
-
(shouldn't that - be a +?)
Note that when |x| < |y| the square root doesn't exist.
Also note that the IEEE/459 floating point format knows about *two* zeros: +0
and -0; the square root of -0 is also a NaN if I'm not mistaken.
kind regards,
Jos
ps. no insult intended, but when you want your software to be maintained,
worked on etc. in an international environment, English variable names are to
be preferred. Really, I've been there, done that.
Basically you're doing: -
Math.sqrt(Math.pow(x, 2)-Math.pow(y, 2))
-
(shouldn't that - be a +?)
Note that when |x| < |y| the square root doesn't exist.
Also note that the IEEE/459 floating point format knows about *two* zeros: +0
and -0; the square root of -0 is also a NaN if I'm not mistaken.
kind regards,
Jos
ps. no insult intended, but when you want your software to be maintained,
worked on etc. in an international environment, English variable names are to
be preferred. Really, I've been there, done that.
You've written software in (what's the Dutch language called) before?
usually i use english names for variables but it's only college project so ...
it's Euclidean Distance i'm counting should be -
You've written software in (what's the Dutch language called) before?
Yep, and my instructor and professor kicked that habit out of me when I was a
youngster ;-)
The Dutch speak Dutch (who'd have thought it!) Afrikaans and Flemish and
Surinaams are all related. (the Flemish even claim that their language *is*
Dutch and the Dutch speak a dialect, which I think is true).
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jason |
last post by:
Hi,
I need a way to use random numbers in c++. In my c++ project, when using
the mingw compiler I used a mersenne twister that is publicly available and
this did its job well. Now I have...
|
by: jose luis fernandez diaz |
last post by:
Hi,
My OS is:
cronos:jdiaz:tmp>uname -a
HP-UX cronos B.11.11 U 9000/800 820960681 unlimited-user license
I compile in 64-bits mode the program below:
|
by: Ben Pfaff |
last post by:
One issue that comes up fairly often around here is the poor
quality of the pseudo-random number generators supplied with many
C implementations. As a result, we have to recommend things like...
|
by: Kishor |
last post by:
Hi Friends
Please help me to write a C program to find the 5th (fifth) root of a given number.
Ex:(1) Input : 32
Output : 5th root of 32 is 2
Ex:(1) Input : 243
Output : 5th root of 243 is...
|
by: Peteroid |
last post by:
I know how to use rand() to generate random POSITIVE-INTEGER numbers.
But, I'd like to generate a random DOUBLE number in the range of 0.0 to 1.0
with resolution of a double (i.e., every possible...
|
by: Pavils Jurjans |
last post by:
Hello,
I am somewhat lost in the implicit/expicit possible/impossible type casting
in C#...
I need to write a class, which among other things, must have wat to read a
numeric value type, and...
|
by: John |
last post by:
I'm new to C and I know this is probably one of those "most commonly
mis-interpreted as a problem", newcomer type of question, but for this code:
double x;
printf("Enter number:");...
|
by: Dancefire |
last post by:
Hi, everyone
It might be a simple question, but I really don't know the answer.
char c = '1';
cout << c;
The above code will only output a '1' rather than 0x31;
If I use int cast, it can...
|
by: jacob navia |
last post by:
Hi
"How can I round a number to x decimal places" ?
This question keeps appearing. I would propose the following
solution
#include <float.h>
#include <math.h>
|
by: Matthias |
last post by:
Dear newsgroup.
I want to write a template function which accepts either integer or
floating point numbers.
If a certain result is not a whole number and if the template
parameter is an...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |