comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: How to calculate the abscissa values for the given vertical values
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: How to calculate the abscissa values for the given vertical values [message #68120] Tue, 06 October 2009 04:04
Maarten[1] is currently offline  Maarten[1]
Messages: 176
Registered: November 2005
Senior Member
On Oct 5, 6:26 pm, "Jean H." <jghas...@DELTHIS.ucalgary.ANDTHIS.ca>
wrote:

> x = findgen(1000)/1000*4*pi
> y = cos(x)
>
> Ytarget = 0
>
> ;Find the 2 consecutive points that are > and < of the Y threshold value
> ;(don't forget to deal where a point = the value)
>
> Xidx = where((y gt Ytarget and shift(y,1) lt Ytarget) or (y lt Ytarget
> and shift(y,1) gt Ytarget), count)

I think this is easier, and possibly faster:
Xidx = where((y-ytarget)*shift(y-ytarget,1) le 0, count)

The multiplication will only be negative if two points straddle the
crossing. The value 0 will be repeated twice if one of the points
matches exactly. These are easy to take out beforehand. The rest is as
before.

> ;y = ax+b
> a = (y[xIdx] - y[xIdx+1]) / (x[xIdx] - x[xIdx+1])
> b = y[xIdx]-a*x[xIdx]
> Xsolution = (yTarget - b)/a

Maarten
Re: How to calculate the abscissa values for the given vertical values [message #68121 is a reply to message #68120] Tue, 06 October 2009 00:55 Go to previous message
duxiyu@gmail.com is currently offline  duxiyu@gmail.com
Messages: 88
Registered: March 2007
Member
On Oct 5, 6:26 pm, "Jean H." <jghas...@DELTHIS.ucalgary.ANDTHIS.ca>
wrote:
> dux...@gmail.com wrote:
>> Y is a time series and X is the sampling time.
>> Both X and Y are discrete.
>> I don't know the analytical form of the relation bewteen X and Y.
>
>> To get the vertical value NY for a given time NX, I can use 'NY =
>> interpol(Y, X NX)'.
>> Similarly, I want to get the correspondent time CX for a fixed
>> vertical value CY.
>> But the values of correspondent time are not unique. CX should be not
>> a scalar but an array.
>> So I cannot use 'CX = interpol(X, Y, CY)' to get these values.
>
> You may do it by hand...
>
> x = findgen(1000)/1000*4*pi
> y = cos(x)
>
> Ytarget = 0
>
> ;Find the 2 consecutive points that are > and < of the Y threshold value
> ;(don't forget to deal where a point = the value)
>
> Xidx = where((y gt Ytarget and shift(y,1) lt Ytarget) or (y lt Ytarget
> and shift(y,1) gt Ytarget), count)
>
> then you can do a linear interpolation to find Xsolution
>
> ;y = ax+b
> a = (y[xIdx] - y[xIdx+1]) / (x[xIdx] - x[xIdx+1])
> b = y[xIdx]-a*x[xIdx]
> Xsolution = (yTarget - b)/a
>
> Jean

Thank you very much! ^_^
Re: How to calculate the abscissa values for the given vertical values [message #68124 is a reply to message #68121] Mon, 05 October 2009 10:55 Go to previous message
pgrigis is currently offline  pgrigis
Messages: 436
Registered: September 2007
Senior Member
On Oct 5, 11:34 am, "dux...@gmail.com" <dux...@gmail.com> wrote:
> Y is a time series and X is the sampling time.
> Both X and Y are discrete.
> I don't know the analytical form of the relation bewteen X and Y.

Ok - then this is much easier and Jean indicated a good approach
- with minor modifcations to take into account the case where
a datapoint is exactly zero.

Ciao,
Paolo

>
> To get the vertical value NY for a given time NX, I can use 'NY =
> interpol(Y, X NX)'.
> Similarly, I want to get the correspondent time CX for a fixed
> vertical value CY.
> But the values of correspondent time are not unique. CX should be not
> a scalar but an array.
> So I cannot use 'CX = interpol(X, Y, CY)' to get these values.
>
> On Oct 5, 4:55 pm, Paolo <pgri...@gmail.com> wrote:
>
>> On Oct 5, 9:43 am, "dux...@gmail.com" <dux...@gmail.com> wrote:
>
>>> Maybe my statement is not clear.
>
>>> There is a function Y=F(X), and I want to calculate the correspondent
>>> abscissa values X for Y=0.
>>> It means that there are serval intersection points between the line Y=F
>>> (X) and the horizonal line Y=0,
>>> and I want to get the correspondent abscissa values of these points.
>
>> You should realize that what you *want* and what you can *achieve*
>> are two different things. This is a hard problem for general F...
>> I believe you should read chapter 9 (on root finding) of the
>> numerical recipes book.
>
>> But - this problem becomes more easy if you do know something about
>> the properties of your function - for instance if you can bracket
>> your solutions - so maybe the question is, what do you know about F?
>
>> Ciao,
>> Paolo
>
>>> On Oct 5, 3:10 pm, Wox <s...@nomail.com> wrote:
>
>>>> On Mon, 5 Oct 2009 01:56:20 -0700 (PDT), "dux...@gmail.com"
>
>>>> <dux...@gmail.com> wrote:
>>>> >Hi, all.
>>>> >I want to calculate the abscissa values for the given vertical values.
>
>>>> >For example,
>>>> >     x = findgen(1000)/1000*4*pi
>>>> >     y = cos(x)
>>>> >I want to get the abscissa values for y=0.
>>>> >For this example, the results shoule be [!pi/2, 3*!pi/2, 5*!pi/2, 7*!
>>>> >pi/2].
>>>> >But how can I get it by IDL codes?
>
>>>> >Best wishes,
>>>> >jdu
>
>>>> Just for this function:
>>>> print,(indgen(ceil(max(x)/!pi))+1)*!pi/2
>
>>>> What do you need exactly? You can always find the answer analytically
>>>> no?
>
>
Re: How to calculate the abscissa values for the given vertical values [message #68126 is a reply to message #68124] Mon, 05 October 2009 09:26 Go to previous message
Jean H. is currently offline  Jean H.
Messages: 472
Registered: July 2006
Senior Member
duxiyu@gmail.com wrote:
> Y is a time series and X is the sampling time.
> Both X and Y are discrete.
> I don't know the analytical form of the relation bewteen X and Y.
>
> To get the vertical value NY for a given time NX, I can use 'NY =
> interpol(Y, X NX)'.
> Similarly, I want to get the correspondent time CX for a fixed
> vertical value CY.
> But the values of correspondent time are not unique. CX should be not
> a scalar but an array.
> So I cannot use 'CX = interpol(X, Y, CY)' to get these values.

You may do it by hand...

x = findgen(1000)/1000*4*pi
y = cos(x)

Ytarget = 0


;Find the 2 consecutive points that are > and < of the Y threshold value
;(don't forget to deal where a point = the value)

Xidx = where((y gt Ytarget and shift(y,1) lt Ytarget) or (y lt Ytarget
and shift(y,1) gt Ytarget), count)


then you can do a linear interpolation to find Xsolution

;y = ax+b
a = (y[xIdx] - y[xIdx+1]) / (x[xIdx] - x[xIdx+1])
b = y[xIdx]-a*x[xIdx]
Xsolution = (yTarget - b)/a

Jean
Re: How to calculate the abscissa values for the given vertical values [message #68128 is a reply to message #68126] Mon, 05 October 2009 08:34 Go to previous message
duxiyu@gmail.com is currently offline  duxiyu@gmail.com
Messages: 88
Registered: March 2007
Member
Y is a time series and X is the sampling time.
Both X and Y are discrete.
I don't know the analytical form of the relation bewteen X and Y.

To get the vertical value NY for a given time NX, I can use 'NY =
interpol(Y, X NX)'.
Similarly, I want to get the correspondent time CX for a fixed
vertical value CY.
But the values of correspondent time are not unique. CX should be not
a scalar but an array.
So I cannot use 'CX = interpol(X, Y, CY)' to get these values.



On Oct 5, 4:55 pm, Paolo <pgri...@gmail.com> wrote:
> On Oct 5, 9:43 am, "dux...@gmail.com" <dux...@gmail.com> wrote:
>
>> Maybe my statement is not clear.
>
>> There is a function Y=F(X), and I want to calculate the correspondent
>> abscissa values X for Y=0.
>> It means that there are serval intersection points between the line Y=F
>> (X) and the horizonal line Y=0,
>> and I want to get the correspondent abscissa values of these points.
>
> You should realize that what you *want* and what you can *achieve*
> are two different things. This is a hard problem for general F...
> I believe you should read chapter 9 (on root finding) of the
> numerical recipes book.
>
> But - this problem becomes more easy if you do know something about
> the properties of your function - for instance if you can bracket
> your solutions - so maybe the question is, what do you know about F?
>
> Ciao,
> Paolo
>
>
>
>> On Oct 5, 3:10 pm, Wox <s...@nomail.com> wrote:
>
>>> On Mon, 5 Oct 2009 01:56:20 -0700 (PDT), "dux...@gmail.com"
>
>>> <dux...@gmail.com> wrote:
>>>> Hi, all.
>>>> I want to calculate the abscissa values for the given vertical values.
>
>>>> For example,
>>>>     x = findgen(1000)/1000*4*pi
>>>>     y = cos(x)
>>>> I want to get the abscissa values for y=0.
>>>> For this example, the results shoule be [!pi/2, 3*!pi/2, 5*!pi/2, 7*!
>>>> pi/2].
>>>> But how can I get it by IDL codes?
>
>>>> Best wishes,
>>>> jdu
>
>>> Just for this function:
>>> print,(indgen(ceil(max(x)/!pi))+1)*!pi/2
>
>>> What do you need exactly? You can always find the answer analytically
>>> no?
>
>
Re: How to calculate the abscissa values for the given vertical values [message #68130 is a reply to message #68128] Mon, 05 October 2009 07:55 Go to previous message
pgrigis is currently offline  pgrigis
Messages: 436
Registered: September 2007
Senior Member
On Oct 5, 9:43 am, "dux...@gmail.com" <dux...@gmail.com> wrote:
> Maybe my statement is not clear.
>
> There is a function Y=F(X), and I want to calculate the correspondent
> abscissa values X for Y=0.
> It means that there are serval intersection points between the line Y=F
> (X) and the horizonal line Y=0,
> and I want to get the correspondent abscissa values of these points.

You should realize that what you *want* and what you can *achieve*
are two different things. This is a hard problem for general F...
I believe you should read chapter 9 (on root finding) of the
numerical recipes book.

But - this problem becomes more easy if you do know something about
the properties of your function - for instance if you can bracket
your solutions - so maybe the question is, what do you know about F?

Ciao,
Paolo

>
> On Oct 5, 3:10 pm, Wox <s...@nomail.com> wrote:
>
>> On Mon, 5 Oct 2009 01:56:20 -0700 (PDT), "dux...@gmail.com"
>
>> <dux...@gmail.com> wrote:
>>> Hi, all.
>>> I want to calculate the abscissa values for the given vertical values.
>
>>> For example,
>>>     x = findgen(1000)/1000*4*pi
>>>     y = cos(x)
>>> I want to get the abscissa values for y=0.
>>> For this example, the results shoule be [!pi/2, 3*!pi/2, 5*!pi/2, 7*!
>>> pi/2].
>>> But how can I get it by IDL codes?
>
>>> Best wishes,
>>> jdu
>
>> Just for this function:
>> print,(indgen(ceil(max(x)/!pi))+1)*!pi/2
>
>> What do you need exactly? You can always find the answer analytically
>> no?
>
>
Re: How to calculate the abscissa values for the given vertical values [message #68131 is a reply to message #68130] Mon, 05 October 2009 06:43 Go to previous message
duxiyu@gmail.com is currently offline  duxiyu@gmail.com
Messages: 88
Registered: March 2007
Member
Maybe my statement is not clear.

There is a function Y=F(X), and I want to calculate the correspondent
abscissa values X for Y=0.
It means that there are serval intersection points between the line Y=F
(X) and the horizonal line Y=0,
and I want to get the correspondent abscissa values of these points.


On Oct 5, 3:10 pm, Wox <s...@nomail.com> wrote:
> On Mon, 5 Oct 2009 01:56:20 -0700 (PDT), "dux...@gmail.com"
>
> <dux...@gmail.com> wrote:
>> Hi, all.
>> I want to calculate the abscissa values for the given vertical values.
>
>> For example,
>>     x = findgen(1000)/1000*4*pi
>>     y = cos(x)
>> I want to get the abscissa values for y=0.
>> For this example, the results shoule be [!pi/2, 3*!pi/2, 5*!pi/2, 7*!
>> pi/2].
>> But how can I get it by IDL codes?
>
>> Best wishes,
>> jdu
>
> Just for this function:
> print,(indgen(ceil(max(x)/!pi))+1)*!pi/2
>
> What do you need exactly? You can always find the answer analytically
> no?
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Earn Free cash From DoEarn
Next Topic: rois

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 20:03:46 PDT 2025

Total time taken to generate the page: 0.04770 seconds