Check difference between two vectors

S

shapper

Hello,

Is it possible given two vectors, A and B, create a third vector, C,
using the following conditions, without a loop?

D = A - B

If D(i) * D(i-1) < 0 and D(i) > 0 then C(i) = 1

If D(i) * D(i-1) < 0 and D(i) < 0 then C(i) = -1

If D(i) * D(i-1) > 0 then C(i) = 0

---

If D(i) * D(i-1) = 0 then

If D(i) * D(i-2) < 0 and D(i) > 0 then C(i) = 1

If D(i) * D(i-2) < 0 and D(i) < 0 then C(i) = -1

If D(i) * D(i-2) > 0 then C(i) = 0

end

Basically I am creating a function that detects when a function
crosses under or over another function or a constant level ...

This was what I came up with ...
.... the second part is because sometimes the values can be equal
before the cross occurs ...

I am trying to make this with vectors.

Thank You,
Miguel
 
S

shapper

Hello,

Is it possible given two vectors, A and B, create a third vector, C,
using the following conditions, without a loop?

D = A - B

If D(i) * D(i-1) < 0 and D(i) > 0 then C(i) = 1

If D(i) * D(i-1) < 0 and D(i) < 0 then C(i) = -1

If D(i) * D(i-1) > 0 then C(i) = 0

---

If D(i) * D(i-1) = 0 then

If D(i) * D(i-2) < 0 and D(i) > 0 then C(i) = 1

If D(i) * D(i-2) < 0 and D(i) < 0 then C(i) = -1

If D(i) * D(i-2) > 0 then C(i) = 0

end

Basically I am creating a function that detects when a function
crosses under or over another function or a constant level ...

This was what I came up with ...
... the second part is because sometimes the values can be equal
before the cross occurs ...

I am trying to make this with vectors.

Thank You,
Miguel

Ooops, forget it. I posted this on the wrong group.

Sorry,
Miguel
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top