// Prints user@host prompt. void print_userhost(char * username, char * hostname, char * current_dir) { printf(ANSI_COLOR_CYAN "[" ANSI_COLOR_RESET); print_blue(username); printf(ANSI_COLOR_BLUE "@" ANSI_COLOR_RESET); print_blue(hostname); printf(" "); print_green(current_dir); printf(ANSI_COLOR_CYAN "]" ANSI_COLOR_RESET); printf(" %% "); }
int main(int argc, const char *argv[]) { char *eq[]={"{x-sin(3/2*(x+y)), y-cos(3/2*(x+y))}", "{x^3+y^2+1, x^2+y^2+2}", "{2*x^2+y, x+2*y+5}", "{3*x^2-1,log(x)+y+3}", //-eq 0 -eps 1e-100 --> ## 2 step 戻る ## 実数解 "{x^2+y^2+x^2-1,x^2+z^2-y,x-z}", //eq 5 ## 2step 戻る ## "{-x+x^2+2*y^2+2*z^2+2*w^2, -y+2*x*y+2*y*z+2*z*w, -z+y^2+2*x*z+2*y*w, -1+x+2*y+2*z+2*w}", //eq 6 ## 2step 戻る ## "{x-10000-y^2,x*y^2-100}", // eq 8 ## 2step 戻る ## "{0.3*x^2-1}", // eq 9 ## 2step 戻る ## "{(3*x-y^2)^3-1000,log(x)^(-1)+2*y-30}", //eq 12 ### 3step 戻る ### "{cos(0.5*x)+cos(y)-1, sin(0.5*x)-sin(y)-1}", //eq31 // x=pi, y=0 ## 2回 2step 戻る ## "{-x+x^2+2*y^2+2*z^2+2*w^2, -y+2*x*y+2*y*z+2*z*w, -z+y^2+2*x*z+2*y*w, -1+x+2*y+2*z+2*w}", //eq 36 4変数 x=1, y=z=w=0 ## 2step 戻る ## "{x^2-y^2-1,x^4-y^4-1999}", // 桁落ち kappa=0.06, 解 x=sqrt(1000),y=sqrt(999) "{x^2+y^2-1, x^2+2*x*y+y^2-2}", // 線形 "{x+y,x*y}", // 線形,零 NULL }; int debug=0,i,m,step_max0=-1,step_max=-1,prec0=53,prec=53,no=0,solve_true=0,info,seed=0,eterm=0,e_prec=2048,e_seed=-1,kappa=26,l=4; double mu=8; func_t *fF=NULL; cmulti **x0=NULL,**x=NULL,**x_true=NULL,**e=NULL; rmulti *eps=NULL,*eps_true=NULL; // init func_t func_eval(func_script("begin(x,y,z,w,v,u)")); // default prec set_default_prec(prec0); // allocate RA(eps); RA(eps_true); // default parameters rset_d(eps,1e-200); rset_s(eps_true,"1e-2000"); // get options i=1; while(i<argc){ if(STR_EQ(argv[i],"--help")) { usage(); } else if(STR_EQ(argv[i],"-v")) { debug=1; } else if(STR_EQ(argv[i],"-vv")) { debug=2; } else if(STR_EQ(argv[i],"-vvv")) { debug=3; } else if(STR_EQ(argv[i],"-true")) { solve_true=1; } else if(STR_EQ(argv[i],"-eterm")) { eterm=1; } else if(i+1<argc && STR_EQ(argv[i],"-mu")) { mu=atof(argv[++i]); } else if(i+1<argc && STR_EQ(argv[i],"-l")) { l=atoi(argv[++i]); } else if(i+1<argc && STR_EQ(argv[i],"-kappa")){ kappa=atoi(argv[++i]); } else if(i+1<argc && STR_EQ(argv[i],"-eq")) { no=atoi(argv[++i]); } else if(i+1<argc && STR_EQ(argv[i],"-n")) { step_max=atoi(argv[++i]); } else if(i+1<argc && STR_EQ(argv[i],"-prec0")){ prec0=atoi(argv[++i]); } else if(i+1<argc && STR_EQ(argv[i],"-prec")) { prec=atoi(argv[++i]); } else if(i+1<argc && STR_EQ(argv[i],"-e-prec")){ e_prec=atoi(argv[++i]); } else if(i+1<argc && STR_EQ(argv[i],"-e-seed")){ e_seed=atoi(argv[++i]); } else if(i+1<argc && STR_EQ(argv[i],"-eps")) { rset_s(eps,argv[++i]); } else if(i+1<argc && STR_EQ(argv[i],"-seed")) { seed=atoi(argv[++i]); } else { usage(); } i++; } // printf("step_max=%d\n",step_max); printf("mu=%g\n",mu); printf("l=%d\n",l); printf("kappa=%d\n",kappa); fF=func_script(eq[no]); printf("fF="); func_print(fF); printf("\n"); m=func_asize(fF); printf("m=%d\n",m); // allocate vectors and matrices set_default_prec(prec0); printf("prec0=%d\n",prec0); CVA(x0,m); CVA(x,m); CVA(x_true,m); CVA(e,m); // set initial vector init_genrand(seed); cvec_set_rand(m,x0,2,-1); cvec_print(m,x0,"x0=","f",6); // solve for true solution printf("#-------------------\n"); cvec_clone(m,x_true,x0); csolve_newton(m,x_true,fF,step_max0,debug); //prec=csolve_newton_adjust(m,x_true,fF,NULL,eps_true,step_max0,mu,l,kappa,debug); cvec_print(m,x_true,"x*=","e",20); cvec_clone(m,x,x_true); // solve if(solve_true){ printf("#-------------------\n"); cvec_clone(m,x,x0); prec=csolve_newton_adjust(m,x,fF,x_true,eps,step_max,mu,l,kappa,debug); cvec_print(m,x,"x=","e",20); } // error printf("#-------------------\n"); printf("prec=%d\n",prec); set_default_prec(prec); cvec_round(m,e,prec); cvec_set_nan(m,e); info=csolve_krawczyk(m,e,x,fF,debug-2); if(info){ print_red(); printf("failed.\n"); } else{ print_green(); printf("succeeded.\n"); } print_reset(); cvec_print(m,e,"e=","e",1); if(eterm){ printf("#-------------------\n"); if(e_seed>=0){ init_genrand(e_seed); cvec_set_rand(m,x,2,-1); } eterm_show(m,x,fF,e_prec,kappa); } // done printf("#-------------------\n"); fF=func_del(fF); func_clear(); RF(eps); CVF(x,m); CVF(e,m); printf("func_new_del_check_sum=%d\n",func_new_del_check_sum()); return 0; }