Group Abstract Group Abstract

Message Boards Message Boards

Ploting on condition

GROUPS:
Hi Everyone
I've got some list {{A1,B1,C1,D1},{A2,B2,C2,D2},{A3,B3,C3,D3},{A4,B4,C4,D4},{A5,B5,C5,D5},…..{An,Bn,Cn,Dn}}.
I'm trying to create a function for filtering out  differences between Bn-1 and Cn or Cn-1 and Bn that are
less than certain  per cent value . Also I’d like to use this function for plotting. For example a function with threshold 10% will filter out differences  less than 10%. If I took  Cn-1 of  100 to Bn of 109 (+9%), there would not be taken  because the move was less than 10%. If I took Cn-1 of  100 to Bn of 110 (+10%), there would be a move from 100 to 110 and  a line from 100 to 110. And the line would extend further on unless difference between Bn and Cn+1 is greater than 10% or more .
How can I use Mathematica to acquire this target ?
Thank  you in advance.
POSTED BY: Artur Kotarski
Answer
9 months ago
Is this anything like what you are looking for?
 In[1]:= data =
 Table[{RandomReal[{1,2}], RandomReal[{1.35,1.65}], RandomReal[{1.35,1.65}], RandomReal[{1,2}]}, {20}]
 
 Out[1]= {
    {1.61555, 1.54121, 1.41361, 1.65261},
    {1.8799, 1.56107, 1.42576, 1.78373},
    {1.2543, 1.63576, 1.35505, 1.17759},
    {1.38954, 1.62712, 1.49634, 1.99046},
    {1.45715, 1.45802, 1.47354, 1.9938},
   {1.96083, 1.4335, 1.51761, 1.26775},
   {1.64853, 1.42011, 1.36215, 1.67745},
   {1.56973, 1.35722, 1.49714, 1.86257},
   {1.50301, 1.63805, 1.58112, 1.85021},
   {1.11028, 1.41526, 1.63507, 1.17726},
   {1.61768, 1.56544, 1.4358, 1.58676},
   {1.18028, 1.56652, 1.44555, 1.29729},
   {1.8237, 1.60931, 1.51301, 1.30859},
   {1.01127, 1.53756, 1.53543, 1.92896},
   {1.58628, 1.63435, 1.57445, 1.64518},
   {1.50125, 1.63471, 1.54999, 1.60091},
   {1.17622, 1.40375, 1.38231, 1.90849},
   {1.96473, 1.59353, 1.55827, 1.37177},
   {1.2098, 1.63267, 1.49444, 1.56277},
   {1.37147, 1.55571, 1.36636, 1.62468}}

In[2]:= filterdata = data//.{h___,{ax_,bx_,cx_,dx_},{ay_,by_,cy_,dy_},t___} /;
    Not[.9 <= bx/cy <= 1.1] || Not[.9 <= by/cx <= 1.1] -> {h, t}

Out[2]= {
  {1.45715, 1.45802, 1.47354, 1.9938},
  {1.96083, 1.4335, 1.51761, 1.26775},
  {1.61768, 1.56544, 1.4358, 1.58676},
  {1.01127, 1.53756, 1.53543, 1.92896},
  {1.58628, 1.63435, 1.57445, 1.64518},
  {1.96473, 1.59353, 1.55827, 1.37177}}

What that does is repeatedly look for any adjacent pair of {ai,bi,ci,di}, {ai+1,bi+1,ci+1,di+1} and if either of the two ratios is too large then both those adjacent pairs are removed from the list.

Hopefully if you manually do this for the example random data set I created you should come up with the same result.

If this doesn't do what you are wanting then perhaps you can find another way to explain what Mathematica should do, perhaps showing an example that includes enough cases to make it clear.
POSTED BY: Bill Simpson
Answer
9 months ago