Math.Log

J

Joe

Hello,

I'm using Math.Log10 to get my numbers on the same scale but I'm running
into a problem with negative values.
Math.Log10(-143.73833558) is returning a NaN.

Is there something else I can use?

Sorry if this might seem obvious but I'm not a math wiz.

Thanks,
Joe
 
A

Alberto Poblacion

Joe said:
I'm using Math.Log10 to get my numbers on the same scale but I'm running
into a problem with negative values.
Math.Log10(-143.73833558) is returning a NaN.

Is there something else I can use?

Sorry if this might seem obvious but I'm not a math wiz.

No, the logarithm of a negative number is not defined in the Real
domain. If you can define more precisely what you mean by "get my numbers on
the same scale" we may be able to suggest an alternative approach.
 
J

Jon Skeet [C# MVP]

A

Alberto Poblacion

Joe said:
What I need is to take a range say 10 to 38456 and divide it up into 5
parts.

... and you want the parts to fit a logarithmic scale, i imagine. You
then want to do the same thing for negative numbers, in such a way that the
scale will be "symetrical" to the positive part. In this case, I suggest
simply taking absolute values and then changing the sign of the result. That
is, if for a positive x you are doing:
double part = Math.Log10(x);
then when x is negative just do:
part = -Math.Log10(-x);
which will give you a "part" between -1 and -5 for x between -10
and -100000.
 
J

\Ji Zhou [MSFT]\

Hello Joe,

I totally agree with Alberto's suggestion. Since the Math.Log method does
not support the negative parameter. We can pass its absolute value as
parameter into the Math.Log method. Please let us to know if the suggestion
works for your scenario or not. If you have any future questions or
concerns, please do not hesitate to let me know. I will try my best to
provide future help.

Have a nice day!

Best regards,
Ji Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
F

Family Tree Mike

But that really goes haywire if your data contains values between 0.0 and
1.0. The log10 of those will be negative.
 
M

Michel Walsh

The log10 kind of repeats itself each order of magnitude. If you have old
graph paper, you can see that it comes with one, two, three or four
'periods', each period similar to each other. If you have three periods,
each period MAY span values from, say 1 to 10, 10 to 100, and 100 to 1000,
OR 10 to 100, 100 to 1000, 1000 to 10 000 OR 0.001 to 0.01, 0.01
to 0.1 and 0.1 to 1 as example. It is your choice, the exact periods are
you to choose (only the first limit can be selected, once it is done, the
other periods follow).

If you have to plot x values from xa to xb, where xa can be negative (and
xb too, by the way), nothing forbid you to make the linear change of
variable (assuming you want 3 periods) which (2 eq with 2 unknowns) leads
to

eta = x * 999 /(xb-xa) + (1-xa*999/(xb-xa))

which now varies from eta = 1 (when x = xa) to eta = 1000 (when x =
xb) always positive, and ready to use the full 3 orders/periods of your
'virtual' log paper.

So, you change your data initially in (x, y) into (eta, y) before you plot
it, with the formula given here up.

You cannot simply use the absolute value of x: that would 'mirror' the axis
if all the x are negative, reversing your graph, and even worse, if some x
are negative and some x positive, that will 'fold' or mix positive and
negative x together: (-5, 6) will be plotted at the same point than (+5,
6). Probably not what you want.



Vanderghast, Access MVP
 
A

Alberto Poblacion

Family Tree Mike said:
But that really goes haywire if your data contains values between 0.0 and
1.0. The log10 of those will be negative.

Certainly. In fact, it will approach "minus infinite" as the values
approach zero. I imagine that this is why the Original Poster specified a
range similar to "10 to 38456", otherwise the idea of directly applying a
logarithmic scale needs to be reconsidered.
 
J

Joe

We have a very wide range of possible numbers coming in. They can
be -15000.90922 to 34000000 and anywhere in between.

We do also have a lot of values very close to 0.
 
A

Alberto Poblacion

Joe said:
We have a very wide range of possible numbers coming in. They can
be -15000.90922 to 34000000 and anywhere in between.

We do also have a lot of values very close to 0.

If the objetive is to break the range of numbers into several parts, you
will have to give some thought as to how you want those parts to be made.
For instance, if you have a number such as 0.001 coming in, its logarithm
will be -3. So it's probably not adequate to be used as a "number of part".
Depending on how you want to group your data you may wish to use a
"mixed" approach where you first apply a fixed criterion to separate the
numbers and then apply a logarithmic scale to some groups. For instance,
first of all divide your numbers into three groups: less than -10,
between -10 and 10, and more than 10. Then apply Logs (as discussed earlier)
to the first and last group to divide them in "parts", while leaving those
in the middle to belong to yet another "part". This may or may not be
adequate for you; it all depends on how you want your numbers classified.
 
J

\Ji Zhou [MSFT]\

Hi Joe,

If your number x can be in the range from -15000.90922 to 34000000, an easy
and simple way is to add 15002 to the x. So all numbers will be in the
range from 1.09078 to 34015002. So, we can use it as the parameter of the
Math.Log10() directly. But I am not sure if this is the best approach to
your demand. As Alberto has indicated, this issue depends on how you want
to classify your numbers. Could you please share what is in your mind, so
we can give future help on this.


Best regards,
Ji Zhou
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
J

\Ji Zhou [MSFT]\

Hello Joe,

I am writing to check the status of the issue on your side. Could you
please let me know if the suggestion works for you or not? If you have any
questions or concerns, please feel free to let me know. I will be more than
happy to be of assistance.

Have a great day!

Best regards,
Ji Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
J

john doe

NaN means "Not a Number"



v-jzh wrote:

Hello Joe,I am writing to check the status of the issue on your side.
08-Oct-08

Hello Joe

I am writing to check the status of the issue on your side. Could you
please let me know if the suggestion works for you or not? If you have any
questions or concerns, please feel free to let me know. I will be more than
happy to be of assistance.

Have a great day

Best regards,
Ji Zhou ([email protected], remove 'online.'
Microsoft Online Community Suppor

================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed)

This posting is provided "AS IS" with no warranties, and confers no rights
=================================================

Previous Posts In This Thread:

Math.Log
Hello

I'm using Math.Log10 to get my numbers on the same scale but I'm running
into a problem with negative values
Math.Log10(-143.73833558) is returning a NaN

Is there something else I can use

Sorry if this might seem obvious but I'm not a math wiz

Thanks
Joe

Re: Math.Log

No, the logarithm of a negative number is not defined in the Real
domain. If you can define more precisely what you mean by "get my numbers on
the same scale" we may be able to suggest an alternative approach.

What I need is to take a range say 10 to 38456 and divide it up into 5 parts.
What I need is to take a range say 10 to 38456 and divide it up into
parts


Re: Math.Log

... and you want the parts to fit a logarithmic scale, i imagine. You
then want to do the same thing for negative numbers, in such a way that the
scale will be "symetrical" to the positive part. In this case, I suggest
simply taking absolute values and then changing the sign of the result. That
is, if for a positive x you are doing
double part = Math.Log10(x)
then when x is negative just do
part = -Math.Log10(-x)
which will give you a "part" between -1 and -5 for x between -10
and -100000.

Re: Math.Log

Yes, I'd expect it to

Log isn't defined for negative numbers. Se
http://msdn.microsoft.com/en-us/library/system.math.log10(VS.85).asp

If you only care about the magnitude, use Math.Log10(Math.Abs(x)

Jon

Hello Joe, I totally agree with Alberto's suggestion. Since the Math.
Hello Joe,

I totally agree with Alberto's suggestion. Since the Math.Log method does
not support the negative parameter. We can pass its absolute value as
parameter into the Math.Log method. Please let us to know if the suggestion
works for your scenario or not. If you have any future questions or
concerns, please do not hesitate to let me know. I will try my best to
provide future help

Have a nice day

Best regards
Ji Zhou ([email protected], remove 'online.'
Microsoft Online Community Suppor

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed)

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

But that really goes haywire if your data contains values between 0.0 and 1.0.
But that really goes haywire if your data contains values between 0.0 and
1.0. The log10 of those will be negative.

:

The log10 kind of repeats itself each order of magnitude.
The log10 kind of repeats itself each order of magnitude. If you have old
graph paper, you can see that it comes with one, two, three or four
'periods', each period similar to each other. If you have three periods,
each period MAY span values from, say 1 to 10, 10 to 100, and 100 to 1000,
OR 10 to 100, 100 to 1000, 1000 to 10 000 OR 0.001 to 0.01, 0.01
to 0.1 and 0.1 to 1 as example. It is your choice, the exact periods are
you to choose (only the first limit can be selected, once it is done, the
other periods follow).

If you have to plot x values from xa to xb, where xa can be negative (and
xb too, by the way), nothing forbid you to make the linear change of
variable (assuming you want 3 periods) which (2 eq with 2 unknowns) leads
to

eta = x * 999 /(xb-xa) + (1-xa*999/(xb-xa))

which now varies from eta = 1 (when x = xa) to eta = 1000 (when x =
xb) always positive, and ready to use the full 3 orders/periods of your
'virtual' log paper.

So, you change your data initially in (x, y) into (eta, y) before you plot
it, with the formula given here up.

You cannot simply use the absolute value of x: that would 'mirror' the axis
if all the x are negative, reversing your graph, and even worse, if some x
are negative and some x positive, that will 'fold' or mix positive and
negative x together: (-5, 6) will be plotted at the same point than (+5,
6). Probably not what you want.



Vanderghast, Access MVP




Re: Math.Log
message
Certainly. In fact, it will approach "minus infinite" as the values
approach zero. I imagine that this is why the Original Poster specified a
range similar to "10 to 38456", otherwise the idea of directly applying a
logarithmic scale needs to be reconsidered.

We have a very wide range of possible numbers coming in. They can be -15000.
We have a very wide range of possible numbers coming in. They can
be -15000.90922 to 34000000 and anywhere in between.

We do also have a lot of values very close to 0.

in message
Re: Math.Log

If the objetive is to break the range of numbers into several parts, you
will have to give some thought as to how you want those parts to be made.
For instance, if you have a number such as 0.001 coming in, its logarithm
will be -3. So it's probably not adequate to be used as a "number of part".
Depending on how you want to group your data you may wish to use a
"mixed" approach where you first apply a fixed criterion to separate the
numbers and then apply a logarithmic scale to some groups. For instance,
first of all divide your numbers into three groups: less than -10,
between -10 and 10, and more than 10. Then apply Logs (as discussed earlier)
to the first and last group to divide them in "parts", while leaving those
in the middle to belong to yet another "part". This may or may not be
adequate for you; it all depends on how you want your numbers classified.

Hi Joe,If your number x can be in the range from -15000.
Hi Joe,

If your number x can be in the range from -15000.90922 to 34000000, an easy
and simple way is to add 15002 to the x. So all numbers will be in the
range from 1.09078 to 34015002. So, we can use it as the parameter of the
Math.Log10() directly. But I am not sure if this is the best approach to
your demand. As Alberto has indicated, this issue depends on how you want
to classify your numbers. Could you please share what is in your mind, so
we can give future help on this.


Best regards,
Ji Zhou
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================

Hello Joe,I am writing to check the status of the issue on your side.
Hello Joe,

I am writing to check the status of the issue on your side. Could you
please let me know if the suggestion works for you or not? If you have any
questions or concerns, please feel free to let me know. I will be more than
happy to be of assistance.

Have a great day!

Best regards,
Ji Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================


Submitted via EggHeadCafe - Software Developer Portal of Choice
BizTalk: Conditional looping incorporating the Greater Than functoid.
http://www.eggheadcafe.com/tutorial...2d-043c18df964c/biztalk-conditional-loop.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Once again Math.Log 7
Y axis log scale flipping 0
simple lookup 3
Type conversion 1
Problem with creating a negative (inverted) image 2
Setting Session Variable From Javascript 2
System.Math.Round bug 2
DataPlotter 3

Top