Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   logarithmic interpolation (http://www.velocityreviews.com/forums/t459899-logarithmic-interpolation.html)

 different 01-18-2007 06:09 PM

logarithmic interpolation

Hi, I have a program which reads a file containing integers in [0,10].
The program reads the value of a variable every 2 seconds, then maps it
to another interval, say [20,22000], obtaining a new value.
I already have a function which updates the variable, gradually
changing from the old one to the new one during the 2 seconds, which
uses a linear function.
Know I need to make the value of the variable change between old and
new in a "logarithmic way", that is the values between old and new must
follow a logarithmic scale.
How can I do that?

 Victor Bazarov 01-18-2007 06:13 PM

Re: logarithmic interpolation

different wrote:
> Hi, I have a program which reads a file containing integers in [0,10].
> The program reads the value of a variable every 2 seconds, then maps
> it to another interval, say [20,22000], obtaining a new value.
> I already have a function which updates the variable, gradually
> changing from the old one to the new one during the 2 seconds, which
> uses a linear function.
> Know I need to make the value of the variable change between old and
> new in a "logarithmic way", that is the values between old and new
> must follow a logarithmic scale.
> How can I do that?

Is there a C++ language question hiding here?

 Mark P 01-18-2007 06:28 PM

Re: logarithmic interpolation

different wrote:
> Hi, I have a program which reads a file containing integers in [0,10].
> The program reads the value of a variable every 2 seconds, then maps it
> to another interval, say [20,22000], obtaining a new value.
> I already have a function which updates the variable, gradually
> changing from the old one to the new one during the 2 seconds, which
> uses a linear function.
> Know I need to make the value of the variable change between old and
> new in a "logarithmic way", that is the values between old and new must
> follow a logarithmic scale.
> How can I do that?
>

First you question is off-topic. Try comp.programming in the future
(followup-to reset).

Besides being off-topic, your question is not well defined. What is "a
logarithmic way"? I'll take a wild guess and suppose you mean log(new)
= m * old + b, for constants m and b. Let 0 map to 20 and 10 map to
22000, then solve for m and b. Then new = exp( m * old + b). Or is
"logarithmic way" supposed to mean something else?

 Richard Herring 01-19-2007 10:39 AM

Re: logarithmic interpolation

In message <eoodco\$9bh\$1@news.datemas.de>, Victor Bazarov
<v.Abazarov@comAcast.net> writes
>different wrote:
>> Hi, I have a program which reads a file containing integers in [0,10].
>> The program reads the value of a variable every 2 seconds, then maps
>> it to another interval, say [20,22000], obtaining a new value.
>> I already have a function which updates the variable, gradually
>> changing from the old one to the new one during the 2 seconds, which
>> uses a linear function.
>> Know I need to make the value of the variable change between old and
>> new in a "logarithmic way", that is the values between old and new
>> must follow a logarithmic scale.
>> How can I do that?

>
>Is there a C++ language question hiding here?

If there is, the answer probably involves <cmath>, std::pow() and
std::log[10]().

--
Richard Herring

 Zbigniew Karno 01-19-2007 03:59 PM

Re: logarithmic interpolation

different napisal(a):
> Hi, I have a program which reads a file containing integers in [0,10].
> The program reads the value of a variable every 2 seconds, then maps it
> to another interval, say [20,22000], obtaining a new value.
> I already have a function which updates the variable, gradually
> changing from the old one to the new one during the 2 seconds, which
> uses a linear function.
> Know I need to make the value of the variable change between old and
> new in a "logarithmic way", that is the values between old and new must
> follow a logarithmic scale.
> How can I do that?

Instead of the function log(x), rather you have
to use the following one: log(x - 1), for x >= 0.

Then the interpolation formula for x in [x_1,x_2]
with ratio f = a/(a+b), looks as follows:

(log(x_2 -1) - log(x - 1)) / (log(x - 1) - log(x_1 - 1)) = (1/f) - 1

After a simple calculation one can get

x = (x_1 - 1)^{f-1} * (x_2 - 1)^{f} + 1 ,

what you expect.

Best Regards,
Z. Karno

 Zbigniew Karno 01-19-2007 05:25 PM

Re: logarithmic interpolation

Zbigniew Karno napisal(a):
> different napisal(a):
> > Hi, I have a program which reads a file containing integers in [0,10].
> > The program reads the value of a variable every 2 seconds, then maps it
> > to another interval, say [20,22000], obtaining a new value.
> > I already have a function which updates the variable, gradually
> > changing from the old one to the new one during the 2 seconds, which
> > uses a linear function.
> > Know I need to make the value of the variable change between old and
> > new in a "logarithmic way", that is the values between old and new must
> > follow a logarithmic scale.
> > How can I do that?

>
>
> Instead of the function log(x), rather you have
> to use the following one: log(x - 1), for x >= 0.
>
> Then the interpolation formula for x in [x_1,x_2]
> with ratio f = a/(a+b), looks as follows:
>
> (log(x_2 -1) - log(x - 1)) / (log(x - 1) - log(x_1 - 1)) = (1/f) - 1
>
> After a simple calculation one can get
>
> x = (x_1 - 1)^{f-1} * (x_2 - 1)^{f} + 1 ,
>
> what you expect.
>
> Best Regards,
> Z. Karno

Incorrect.
The sign - should be replaced by +.

So, the following function has to be used:
log(x + 1), for x >= 0.
In this case, the interpolation formula looks as
follows:
(log(x_2 +1) - log(x + 1)) / (log(x + 1) - log(x_1 + 1)) = (1/f) -
1.
Thus
x = (x_1 + 1)^{f -1} * (x_2 + 1)^{f} - 1 .

Regards,
Z. Karno

 All times are GMT. The time now is 04:50 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.