-2

How to check whether the curve is C1 class or C2 class.

Example:

x = [1,2,3,4,5,6,7,8,9 ......1500] 

y = [0.56, 1, 12, 41, 01. ....... 11, 0.11, 3, 23, 95] 

This curve is C1 class "function" ?

Thank you very much.

eykanal
  • 26,437
  • 19
  • 82
  • 113
flatronka
  • 1,061
  • 25
  • 51
  • 1
    Does C1 refer to continuity order? C1 means first derivative continuous and C2 2nd derivative continuous to me. Is that what it means to you? – duffymo Oct 26 '11 at 18:35
  • yes exactly :) thanks your answer. But how can check this in Matlab Curve? – flatronka Oct 26 '11 at 18:43

3 Answers3

4

MatLab vectors contain samples of the function, not the function itself.

Sampled data is always discrete, not continuous.

There are infinitely many functions with the same samples. Specifically, there are always both continuous and discontinous functions with those samples, so there's no way to determine C1 or not from just samples.


Example of a continuous function: The Fourier (or DCT) reconstructed estimate.

Example of a discontinuous function: The Fourier reconstructed estimate, plus a sawtooth wave with period equal to the sampling rate.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • :( okay, but i must check my 10k randomly generate sample that is it possible C1 class. Is it impossible? Thanks your reply. – flatronka Oct 26 '11 at 19:10
  • This point list has one to one relation, and not joined together, the y just randomly generated vector, the x is the subdivison of the curve. I want to approximate a C1 or C2 functional with an extremal curve. – flatronka Oct 26 '11 at 19:52
  • As everybody has said, it is impossible to know. –  Oct 26 '11 at 22:27
3

You can't tell from the data you're given; you have to know something about how you represent a function from it.

For example, if I plot those as a histogram it's discontinuous (jumps at each point). If I do straight line interpolation between points it's C0 continuous. If I use a smooth interpolation like a spline I can get C1 continuity and so on depending on how I choose to represent the function from your arrays of data.

duffymo
  • 305,152
  • 44
  • 369
  • 561
  • I'm trying to figure out exactly what you said that I didn't already cover that earned you an upvote... – Ben Voigt Oct 26 '11 at 21:38
  • I don't know, I didn't read your answer. I know my comment about the meaning of C1 and C2 was the first response of any kind. If you feel slighted, perhaps you'll feel better if I vote your answer up. – duffymo Oct 26 '11 at 22:39
  • Your comment was most definitely first, otherwise I wouldn't have known what he was talking about. (Usually I assume people aren't trying to do the impossible) – Ben Voigt Oct 26 '11 at 23:20
  • yes, for example the hermit interpolation show's the C1 class state. the y,y' is randomly generated vector but the first and last element in the vectors is given. Given x the subdivison of the curve, y generated randomly, y' generated randomly, but y(1),y(n), y(1)',y(n)' is given. If the function has big jumps the interpolation can't generate result. – flatronka Oct 30 '11 at 13:40
  • Sorry deszhtop, this makes no sense whatsoever. Your data arrays are x and y; there's no mention of y' that I can see. You're making that up. – duffymo Nov 01 '11 at 20:24
  • I know, i realized. Thanks all reply. – flatronka Nov 02 '11 at 17:50
-1

While technically you can't check if the data corresponds to a C1 or C2 curve - you can do something that still might be useful.

C1 means continuous 1st derivative. So if you calculate the derivative numerically and then see big jumps in the derivative then you might suspect that the underlying curve is not C1. (You can't actually guarantee that, but you can guarantee that it is either not C1 or has derivative outside some bounds). Conversely if you don't get any big jumps then there is a C1 curve with bounded derivative that does fit the data - just not necessarily the same curve that actually generated the data.

You can do something similar with the numerically calculated second derivative to determine its C2 status. (Note that if its not C1, then it can't be C2 - so if that test fails you can forget about the second test.)

Here's roughly how I'd do it in C++ for the C1 case with evenly spaced x points. (If things are not evenly spaced you'll need to tweak the calculation of s).

double y[N] = {0.56, 1, 12, 41, ..., 11, 0.11, 3, 23, 95 };

double max_abs_slope = 0;
double sum_abs_slope = 0;
double sum_abs_slope_sq = 0;
unsigned int imax=0;

for(unsigned int i=0; i<N-1; ++i )
{
  double s = fabs( y[i+1]-y[i] );
  sum_abs_slope += s;
  sum_abs_slope_sq += s*s;
  if(s>max_abs_slope) { max_abs_slope = s; imax = i; }
}

// We expect the max to be within three std-dev of the average.
double stddev = sqrt(  (N*sum_abs_slope_sq - sum_abs_slope*sum_abs_slope)/(N*(N-1)) );

if( ( max_abs_slope - sum_abs_slope/(N-1) ) > 3 * stddev )
{  
   std::cout<<"There's an unexpectedly large jump in interval "<<imax<<std::endl;
}
else
{
   std::cout<<"It seems smooth"<<std::endl;
}

However you might use a different threshold than 3*stddev, you might pick an actual limit based on your knowledge of the underlying problem, or you might choose to be stricter (using a value >3) or less strict (<3).

I've not tested this code, so it may not run or may be buggy. I've also not checked that 3*stddev makes sense for any curves. This is very much caveat emptor.

Michael Anderson
  • 70,661
  • 7
  • 134
  • 187