update
This commit is contained in:
@@ -7,6 +7,6 @@
|
||||
#define M (0.5*Rs)
|
||||
#define R0 (15*Rs)
|
||||
#define f(r) ((1.0-Rs/((double)r)))
|
||||
#define bmin (1.5*sqrt(3.0))+1e-5
|
||||
#define bmin (1.5*sqrt(3.0)+5e-10)
|
||||
#define THETAERROR 100000
|
||||
|
||||
|
||||
27
src/init.c
27
src/init.c
@@ -85,7 +85,7 @@ double chi(double b){
|
||||
printf("Error: GSL driver returns %d\n", status);
|
||||
break;
|
||||
}
|
||||
//printf("phi: %g, y[0]: %g, y[1]: %g\n",phi, y[0], y[1]);
|
||||
printf("phi: %g, y[0]: %g, y[1]: %g\n",phi, y[0], y[1]);
|
||||
}
|
||||
|
||||
//printf("%g, %g \n",find_root(y_previous, phi_previous),find_root(y, phi));
|
||||
@@ -113,11 +113,17 @@ void sample_push(SampleData *sample, double x, double y){
|
||||
}
|
||||
|
||||
static void refine_interval(double xl, double xr, double yl, double yr, double rela_err_limit, SampleData *sample){
|
||||
printf("calculating interval (%g, %g)\n", xl, xr);
|
||||
double xm = (xl + xr)/2;
|
||||
double ym = chi(xm);
|
||||
sample_push(sample, xm, ym);
|
||||
if (fabs((ym-(yl+yr)/2)/ym) >= rela_err_limit) {
|
||||
int need_refine = (fabs(ym-(yl+yr)/2) >= fabs(rela_err_limit * ym));
|
||||
if (need_refine) {
|
||||
printf(" ");
|
||||
refine_interval(xl, xm, yl, ym, rela_err_limit, sample);
|
||||
}
|
||||
sample_push(sample, xm, ym);
|
||||
if (need_refine) {
|
||||
printf(" ");
|
||||
refine_interval(xm, xr, ym, yr, rela_err_limit, sample);
|
||||
}
|
||||
return ;
|
||||
@@ -125,16 +131,17 @@ static void refine_interval(double xl, double xr, double yl, double yr, double r
|
||||
|
||||
int init(double bmax, double rela_err_limit){
|
||||
SampleData sample;
|
||||
sample.capacity = 2;
|
||||
sample.size=2;
|
||||
sample.x = malloc(sizeof(double) * 2);
|
||||
sample.y = malloc(sizeof(double) * 2);
|
||||
sample.capacity = 1;
|
||||
sample.size=1;
|
||||
sample.x = malloc(sizeof(double) * 1);
|
||||
sample.y = malloc(sizeof(double) * 1);
|
||||
sample.x[0] = bmin;
|
||||
sample.x[1] = bmax;
|
||||
sample.y[0] = chi(bmin);
|
||||
sample.y[1] = chi(bmax);
|
||||
double chi_bmax = chi(bmax);
|
||||
|
||||
refine_interval(bmin, bmax, sample.y[0], sample.y[1], rela_err_limit, &sample);
|
||||
refine_interval(bmin, bmax, sample.y[0], chi_bmax, rela_err_limit, &sample);
|
||||
|
||||
sample_push(&sample, bmax, chi_bmax);
|
||||
|
||||
//sort
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
#include "init.h"
|
||||
|
||||
int main(){
|
||||
init(15.0, 1e-3);
|
||||
//init(15.0, 1e-1);
|
||||
chi(bmin);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user