Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > 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
 
 
 
 
Martin Ambuhl
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?


This is not a question about C but about elementary arithmetic. I will
offer an explanation but it is al; off-topic in comp.lang.c and should
not be replied to.

<ot>
You are looking for a function that maps a linear variable x onto an
exponential variable y.
y = A*exp(bx)
using a for log(A), this is the same as
log(y) = a + bx
We have a form with two unknowns and we have two data points:
log(20) = a + 0*b
log(22000) = a + 10b
so we know immediately that
a = log(20)
or A = 20
and that
b = (log(22000) - log(20)) / 10
or
b = log(1100) / 10
so the mapping is
log(y) = log(20) + x * log(1100)/10

y = 20 * pow(1100, x/10);

</ot>
 
Reply With Quote
 
 
 
 
David T. Ashley
Guest
Posts: n/a
 
      01-18-2007
"different" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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?


sci.math and related groups have a large pool of bored mathematicians and
students who will gladly address such topics.

--
David T. Ashley ((E-Mail Removed))
http://www.e3ft.com (Consulting Home Page)
http://www.dtashley.com (Personal Home Page)
http://gpl.e3ft.com (GPL Publications and Projects)


 
Reply With Quote
 
user923005
Guest
Posts: n/a
 
      01-19-2007
David T. Ashley wrote:
> "different" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
> > 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?

>
> sci.math and related groups have a large pool of bored mathematicians and
> students who will gladly address such topics.


They might even point him to this:
http://www.mpip-mainz.mpg.de/~desern...og_interpol.ps

> --
> David T. Ashley ((E-Mail Removed))
> http://www.e3ft.com (Consulting Home Page)
> http://www.dtashley.com (Personal Home Page)
> http://gpl.e3ft.com (GPL Publications and Projects)


 
Reply With Quote
 
different
Guest
Posts: n/a
 
      01-19-2007
Sorry, I know that it was OT, but I always tried sci.math and another
forum about algorithms, but they did not give me an answer in one week.
Thank you for the reply.

On 18 Gen, 19:26, Martin Ambuhl <(E-Mail Removed)> wrote:
> 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?This is not a question about C but about elementary arithmetic. I will

> offer an explanation but it is al; off-topic in comp.lang.c and should
> not be replied to.
>
> <ot>
> You are looking for a function that maps a linear variable x onto an
> exponential variable y.
> y = A*exp(bx)
> using a for log(A), this is the same as
> log(y) = a + bx
> We have a form with two unknowns and we have two data points:
> log(20) = a + 0*b
> log(22000) = a + 10b
> so we know immediately that
> a = log(20)
> or A = 20
> and that
> b = (log(22000) - log(20)) / 10
> or
> b = log(1100) / 10
> so the mapping is
> log(y) = log(20) + x * log(1100)/10
>
> y = 20 * pow(1100, x/10);
>
> </ot>


 
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++ 5 01-19-2007 05:25 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