Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > logarithmic interpolation

Reply
Thread Tools

logarithmic interpolation

 
 
different
Guest
Posts: n/a
 
      01-18-2007
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?

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      01-18-2007
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?


 
Reply With Quote
 
 
 
 
Mark P
Guest
Posts: n/a
 
      01-18-2007
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?
 
Reply With Quote
 
Richard Herring
Guest
Posts: n/a
 
      01-19-2007
In message <eoodco$9bh$(E-Mail Removed)>, Victor Bazarov
<(E-Mail Removed)> 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:ow() and
std::log[10]().

--
Richard Herring
 
Reply With Quote
 
Zbigniew Karno
Guest
Posts: n/a
 
      01-19-2007

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

 
Reply With Quote
 
Zbigniew Karno
Guest
Posts: n/a
 
      01-19-2007

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Matplotlib logarithmic scatter plot Derek Basch Python 9 11-03-2010 07:30 PM
logarithmic interpolation different C Programming 6 01-19-2007 05:24 PM
Logarithmic RAW images Alfred Molon Digital Photography 16 03-07-2004 10:25 PM
logarithmic cameras (SLR or otherwise) jonathan Digital Photography 6 12-30-2003 08:28 PM
Drawing a logarithmic histogram Andre C Programming 1 07-17-2003 04:40 AM



Advertisments