コード例 #1
0
ファイル: fractal.c プロジェクト: abelsiqueira/fractal
void fractal (options *opt) {
  double hx = (2*opt->r)/opt->width;
  double hy = (2*opt->r)/opt->height;
  int i, j, k;
  int s = 0;
  int max = 1;
  double scale = ((double)opt->width)/opt->height;
  FILE *S = fopen("sol.b","w");
  FILE *K = fopen("iters.b","w");
  double rx = opt->r, ry = opt->r;
  point p;

  if (scale > 1) {
    hx *= scale;
    rx *= scale;
  } else if (scale < 1) {
    hy /= scale;
    ry /= scale;
  }

  for (j = 0; j < opt->height; j++) {
    for (i = 0; i < opt->width; i++) {
      p.x = opt->cx - rx + i*hx;
      p.y = opt->cy - ry + j*hy;
#ifdef VERBOSE
      printf("C=(%lf,%lf), ", p.x, p.y);
#endif
      k = iterative_method(&p, opt);
      s = close_to_solution(&p, opt);
#ifdef VERBOSE
      printf("k = %d, s = %d\n", k, s);
#endif
      fprintf(S, "%d ", s);
      fprintf(K, "%d ", k);
      if (opt->simple == 0 && fabs(k) > max)
        max = fabs(k);
    }
  }
  fclose(S);
  fclose(K);

  printf("max = %d\n", max);

  writefile(max, opt);
}
コード例 #2
0
void get_inputs_and_solve(int* p_sle_solver){
    Matrix *matrix, *initial_guess, *solution_matrix, *roots;
    int rows, columns, single_column = 1, iter, error, error_code = 0;

    get_row_col(&rows, &columns,
                "Enter no. of rows of coefficient matrix: ",
                "Enter no. of columns of coefficient matrix: ",
                "Error! Coefficient matrix is not a square matrix. Try again.\n",
                is_square_matrix);
    
    printf("\n");
    matrix = get_input_matrix(&rows, &columns, 1, 1, 'A');
    display_matrix(matrix, "Coefficient Matrix A: \n");
    
    printf("\nEnter solution matrix values: \n");
    solution_matrix = get_input_matrix(&rows, &single_column, 0, 0, 'C');
    display_matrix(solution_matrix, "\nSolution Matrix C: \n");
    
    printf("\nEnter unknown matrix initial guesses: \n");
    initial_guess = get_input_matrix(&rows, &single_column, 0, 0, 'X');
    display_matrix(initial_guess, "\nInitial Unknown Matrix X: \n");
    
    get_iter_error(&iter, &error);
    
    roots = iterative_method(p_sle_solver, matrix, initial_guess, 
                             solution_matrix, &iter, &error, display_iteration, &error_code);
    
    if(0 == roots && error_code == 1)
        printf("Division by zero.\n");
    else{
        printf("The unknowns of the system of equations are:\n\n");
        display_roots(roots, 'x');
        mtx_delete_matrix(roots);
    }
    
    mtx_delete_matrix(matrix);
    mtx_delete_matrix(solution_matrix);
    mtx_delete_matrix(initial_guess);
}