compute derivative coefficient of n-th degree polynomial equation

 #include <stdio.h>  
 #define ELE 4  
   
 int main()  
 {  
  int i;  
  int g = 3; //degree  
  double c[ELE][3] = {{1, 5, 9},   
                      {2, 6, 10},  
                      {3, 7, 11},  
                      {4, 8, 12}};   
    
  //ELE coefficient of parametric equation  
  //eg ELE == 0 4x^3 + 3x^2 + 2x + 1 2d element of array is x, y, z  
    
  for(int i=0; i<ELE; i++)  
  {  
   for(int j=0; j<3; j++)  
     printf("%.1f ", c[i][j]);  
   printf("\n");  
  }  
  printf("\n--\n");  
   
  //derivative  
  int n = 2; //n-th derivative   
  for(int drv=1; drv<=n; drv++)  
   for(i=g; i>=0; i--)  
     for(int axs=0; axs<3; axs++) //if we want the derivative not be 3 dimensional parametric equation delete this loop  
      c[i][axs]=c[i][axs]*(i-(drv-1));  
  //derivative  
   
  for(int i=0; i<ELE; i++)  
  {  
   for(int j=0; j<3; j++)  
     printf("%.1f ", c[i][j]);  
   printf("\n");  
  }  
   

No comments