vibrating_membrane2.c
void wave2d_vf(double t,double* x,double* rv) {
  int i; // 0 <= i <= Y_DIM-1 , i=row (ver pos)
  int j; // 0 <= j <= X_dim-1 , j=col (hor pos)
  double u,d,l,r; // forces from up down left right
  double displ; // current position displacement
  for(i=0;i<Y_DIM;++i) {
    for(j=0;j<X_DIM;++j) {
      // derivative of first half equal the second half
      rv[i*X_DIM+j]=x[i*X_DIM+j+XY_DIM];
      // now the forces
      displ=x[i*X_DIM+j];
      if(i==0) {
	u=-C*displ;
	d=C*(x[(i+1)*X_DIM+j]-displ);
      }
      else if(i==Y_DIM-1) {
	u=C*(x[(i-1)*X_DIM+j]-displ);
	d=-C*displ;
      }
      else {
	u=C*(x[(i-1)*X_DIM+j]-displ);
	d=C*(x[(i+1)*X_DIM+j]-displ);
      }
      if(j==0) {
	l=-C*displ;
	r=C*(x[i*X_DIM+j+1]-displ);
      }
      else if(j==X_DIM-1) {
	l=C*(x[i*X_DIM+j-1]-displ);
	r=-C*displ;
      }
      else {
	l=C*(x[i*X_DIM+j-1]-displ);
	r=C*(x[i*X_DIM+j+1]-displ);
      }
      	
      rv[i*X_DIM+j+XY_DIM]=u+d+l+r;
    }
  }
}
/*

forces are spring forces
with no damping
the wave2d_vf is the 1st order ODE
coming from the F=ma 2nd order ODE
first X_DIM*Y_DIM variables are displacements of points
second X_DIM*Y_DIM variables are velocities of points

*/
forces are spring forces
with no damping
the wave2d_vf is the 1st order ODE
coming from the F=ma 2nd order ODE
first X_DIM*Y_DIM variables are displacements of points
second X_DIM*Y_DIM variables are velocities of points
forces are spring forces with no damping the wave2d_vf is the 1st order ODE coming from the F = ma 2nd order ODE first X_DIM * Y_DIM variables are displacements of points second X_DIM * Y_DIM variables are velocities of points
void wave2d_vf(double t,double* x,double* rv) {
  int i; 
  int j; 
  double u,d,l,r; 
  double displ; 
  for(i=0;i<Y_DIM;++i) {
    for(j=0;j<X_DIM;++j) {
      rv[i*X_DIM+j]=x[i*X_DIM+j+XY_DIM];
      displ=x[i*X_DIM+j];
      if(i==0) {
	u=-C*displ;
	d=C*(x[(i+1)*X_DIM+j]-displ);
      }
      else if(i==Y_DIM-1) {
	u=C*(x[(i-1)*X_DIM+j]-displ);
	d=-C*displ;
      }
      else {
	u=C*(x[(i-1)*X_DIM+j]-displ);
	d=C*(x[(i+1)*X_DIM+j]-displ);
      }
      if(j==0) {
	l=-C*displ;
	r=C*(x[i*X_DIM+j+1]-displ);
      }
      else if(j==X_DIM-1) {
	l=C*(x[i*X_DIM+j-1]-displ);
	r=-C*displ;
      }
      else {
	l=C*(x[i*X_DIM+j-1]-displ);
	r=C*(x[i*X_DIM+j+1]-displ);
      }
      rv[i*X_DIM+j+XY_DIM]=u+d+l+r;
    }
  }
}
void wave2d_vf ( double t , double * x , double * rv ) { int i ; int j ; double u , d , l , r ; double displ ; for ( i = 0 ; i < Y_DIM ; ++ i ) { for ( j = 0 ; j < X_DIM ; ++ j ) { rv [ i * X_DIM + j ] = x [ i * X_DIM + j + XY_DIM ] ; displ = x [ i * X_DIM + j ] ; if ( i == 0 ) { u = - C * displ ; d = C * ( x [ ( i + 1 ) * X_DIM + j ] - displ ) ; } else if ( i == Y_DIM - 1 ) { u = C * ( x [ ( i - 1 ) * X_DIM + j ] - displ ) ; d = - C * displ ; } else { u = C * ( x [ ( i - 1 ) * X_DIM + j ] - displ ) ; d = C * ( x [ ( i + 1 ) * X_DIM + j ] - displ ) ; } if ( j == 0 ) { l = - C * displ ; r = C * ( x [ i * X_DIM + j + 1 ] - displ ) ; } else if ( j == X_DIM - 1 ) { l = C * ( x [ i * X_DIM + j - 1 ] - displ ) ; r = - C * displ ; } else { l = C * ( x [ i * X_DIM + j - 1 ] - displ ) ; r = C * ( x [ i * X_DIM + j + 1 ] - displ ) ; } rv [ i * X_DIM + j + XY_DIM ] = u + d + l + r ; } } }
forces are spring forces
with no damping
the wave2d_vf is the 1st order ODE
coming from the F=ma 2nd order ODE
first X_DIM*Y_DIM variables are displacements of points
second X_DIM*Y_DIM variables are velocities of points
forces are spring forces with no damping the wave2d_vf is the 1st order ODE coming from the F = ma 2nd order ODE first X_DIM * Y_DIM variables are displacements of points second X_DIM * Y_DIM variables are velocities of points
// 0 <= i <= Y_DIM-1 , i=row (ver pos) // 0 <= j <= X_dim-1 , j=col (hor pos) // forces from up down left right // current position displacement // derivative of first half equal the second half // now the forces