C lang. -- Error: Segmentation fault

Posted by user233542 on Stack Overflow See other posts from Stack Overflow or by user233542
Published on 2010-05-02T22:04:12Z Indexed on 2010/05/02 22:27 UTC
Read the original article Hit count: 276

Filed under:
|

I don't understand why this would give me a seg fault. Any ideas?

This is the function that returns the signal to stop the program (plus the other function that is called within this):

double bisect(double A0,double A1,double Sol[N],double tol,double c)
{
  double Amid,shot;

  while (A1-A0 > tol) {
    Amid = 0.5*(A0+A1);

    shot = shoot(Sol, Amid, c);

    if (shot==2.*Pi) {
      return Amid;
    }

    if (shot > 2.*Pi){
      A1 = Amid;
    }
    else if (shot < 2.*Pi){
      A0 = Amid;
    }
  }

  return 0.5*(A1+A0);
}

double shoot(double Sol[N],double A,double c)
{
  int i,j;

  /*Initial Conditions*/
  for (i=0;i<buff;i++)
    {
      Sol[i] = 0.;
    }
  for (i=buff+l;i<N;i++)
    {
      Sol[i] = 2.*Pi;
    }
  Sol[buff]= 0;
  Sol[buff+1]= A*exp(sqrt(1+3*c)*dx);


  for (i=buff+2;i<buff+l;i++)
    {
      Sol[i] = (dx*dx)*( sin(Sol[i-1]) + c*sin(3.*(Sol[i-1])) )
 - Sol[i-2] + 2.*Sol[i-1];
    }

  return Sol[i-1];
}

The values buff, l, N are defined using a #define statement. l = 401, buff = 50, N = 2000

© Stack Overflow or respective owner

Related posts about segmentation-fault

Related posts about c