Determining if graph is convex -


i trying determine whether line drawn connecting number of points convex or not. points can plotted on x,y coordinates. can done in way other connecting each point every other point , seeing if of lines lie above curve? thanks! here sample points:

x           y 1191.06     0.9655265  1192.36     0.9644738  1193.75     0.9633508  1194.98     0.9623592  1196.49     0.9611447  1197.78     0.9601095 1199.02     0.9591166  1200.29     0.9581017  1201.56     0.9570891  1202.77     0.9561263  1204.01     0.9551415  1205.26     0.9541510   

convex function

a differentiable function of 1 variable convex on interval if , if derivative monotonically non-decreasing on interval. if function differentiable , convex continuously differentiable. basic case of differentiable function (a subset of) real numbers real numbers, "convex" equivalent "increasing @ increasing rate".

you can iterate on points , check slope between each pair of successive points in sequence strictly non-decreasing. don't have connect each point every other point.

pseudo code:

boolean isconvex(float[] x, float[] y, int length) {     float previousslope = 0;     for(int = 1; < length; i++)     {         if(x[i] == x[i-1])         {             // handle infinite gradients avoid div 0             // if not going exclude case data         }         float slope = (y[i] - y[i-1]) / (x[i] - x[i-1]);         // compare slope after first iteration:         if((i > 1) && (slope < previousslope))             return false;         previousslope = slope;     }     return true; } 

this assumes y function of x, , values in arrays sorted ascending order based on x , x monotonically increasing.


Comments

Popular posts from this blog

python - Mongodb How to add addtional information when aggregating? -

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

java - Incorrect order of records in M-M relationship in hibernate -