int main() { int i; Complex cx; History hist; complex_init(&cx); history_init(&hist); srand(time(0)); read_asc(&cx, stdin); complex_compute_free_faces(&cx); printf("checking "); printf("%s", cx.serialized); printf("\n"); complex_print(&cx); fflush(stdout); for (i = 0; i < 100000; ++i) { if (!(i % 1000)) printf("%d\n", i); if (complex_collapse_random(&cx, &hist)) { printf("collapsed! yay!\n"); history_print(&hist); return 0; } } history_destroy(&hist); return 0; }
void test() { complex a, b; a.x = 2.0; a.y = 3.0; b.x = 4; b.y = 5; printf("Enter a and b where a + ib is the first complex number.\n"); printf("a = "); scanf("%f", &a.x); printf("b = "); scanf("%f", &a.y); printf("Enter c and d where c + id is the second complex number.\n"); printf("c = "); scanf("%f", &b.x); printf("d = "); scanf("%f", &b.y); printf (" The complex numbers entered are :%.1f %+.1f and %.1f %+.1fi\n", a.x,a.y,b.x,b.y); printf ("The multiplication of complex numbers are :%.1f %+.1fi\n", mult2(a,b).x, mult2(a,b).y); printf ("The square of complex number is :%.1f %+.1fi\n", square(a).x, square(a).y); printf ("The addition of complex numbers are :%.1f %+.1fi\n", add2(a,b).x, add2(a,b).y); printf ("The juliamap of complex numbers are :%.1f %+.1fi\n", juliamap(a,b).x, juliamap(a,b).y); complex_print(a); complex_print(b); }
void test(){/*this function demonstrates that all of the functions defined above,work correctly.*/ a.x=1.; a.y=3.; b.x=2.; b.y=1.; c=mult2(a,b); assert(c.x==-1.); assert(c.y==7.); printf("mult2 is correct.\n"); c=square(a); assert(c.x==-8.); assert(c.y==6.); printf("square is correct.\n"); c=add2(a,b); assert(c.x==3.); assert(c.y==4.); printf("add2 is correct.\n"); c=juliamap(a,b); assert(c.x==-6.); assert(c.y==7.); printf("juliamap is correct.\n"); complex_print(a); printf("If the previous sentence is 'z=1.000000+3.000000i', the function complex_print is working correctly.\n"); }
void test() { /* From now on, we will be using . right after an integer in order to be in full agreement with the definition of * my x_realpart and y_imagpart since they were defined as long double */ COMPLEX compl1; compl1.x_realpart = 1.; compl1.y_imagpart = 2.; COMPLEX compl2; compl2.x_realpart = 3.; compl2.y_imagpart = 4.; /* let's test */ /* let's compute the multipliction*/ COMPLEX expected1; expected1.x_realpart = -5.; /* this is the real part of the complex number obtained by computing 1+2i and 3+4i*/ expected1.y_imagpart = 10.; /* this is the imaginary part of the complex number obtained by computing 1+2i and 3+4i */ COMPLEX result1; COMPLEX *cptr11, *cptr12; cptr11 = &compl1; cptr12 = &compl2; result1 = mult2(cptr11,cptr12); /*complex_print(result1)*/; /* print the result of the multiplication of two complex numbers*/ assert (expected1.x_realpart == result1.x_realpart); assert (expected1.y_imagpart == result1.y_imagpart); /* let's compute the square of the first complex given above */ COMPLEX expected2; expected2.x_realpart = -3.; /* this is the real part of the complex number obtained by squaring 1+2i*/ expected2.y_imagpart = 4.; /* this is the imaginary part of the complex number obtained by squaring 1+2i*/ COMPLEX result2; COMPLEX *cptr2; cptr2 = &compl1; result2 = square(cptr2); /*complex_print(result2)*/; /* print the result of the square of compl1*/ assert (expected2.x_realpart == result2.x_realpart); assert (expected2.y_imagpart == result2.y_imagpart); /* let's compute the addition of two complex numbers */ COMPLEX expected3; expected3.x_realpart = 4.; /* this is the real part of the complex number obtained by adding 1+2i and 3+4i*/ expected3.y_imagpart = 6.; /* this ia the imag part of the complex number obtained by adding 1+2i and 3+4i*/ COMPLEX result3; COMPLEX *cptr31, *cptr32; cptr31 = &compl1; cptr32 = &compl2; result3 = add2(cptr31,cptr32); /*complex_print(result3)*/; /* print the result of the addition of compl1 and compl2*/ assert (expected3.x_realpart == result3.x_realpart); assert (expected3.y_imagpart == result3.y_imagpart); /* let's compute the juliamap where z= compl1 is the first variable and c= compl2 is the second variable*/ COMPLEX expected4; expected4.x_realpart = 0.; /* this is the real part of the complex number obtained by adding the square of compl1 to compl2*/ expected4.y_imagpart = 8.; /* this is the imag part of the complex number obtained by adding the square of compl1 to compl2*/ COMPLEX result4; COMPLEX *cptr41, *cptr42; cptr41 = &compl1; cptr42 = &compl2; result4 = juliamap(cptr41,cptr42); /*complex_print(result4)*/; /* print the result of the juliamap*/ assert (expected4.x_realpart == result4.x_realpart); assert (expected4.y_imagpart == result4.y_imagpart); /* let's compute the complex_return function with compl1 as the argument*/ COMPLEX expected5; expected5.x_realpart = 1.; expected5.y_imagpart = 2.; COMPLEX *cptr5; cptr5 = &expected5; complex_print(cptr5); printf(" if the previous sentence is z = 1.000000+2.000000i, then the complex return is working as expected \n" ); }
int main(){ int ix,iy,radius,i,tries,nit; double zx,zy,zxn,zyn,cx,cy,theta, x,y,eps, poly[MAX_ROOTS+1]; _roots roots; _complex z,w,fz,dfz; root_init(&roots); // Number of iteration for each pointer. // The bigger, the less prone to error the program will be. nit=100; // The radius where the points will be looked for. radius=6; // Precision for the roots eps=1E-10; scanf("%d",&roots.grad); for(i=roots.grad;i>=0;i--){ scanf("%lf",&poly[i]); } printf("Coefficients:\n"); for(i=roots.grad;i>=0;i--){ printf(" a%d=%+.2f\n",i,poly[i]); } printf("\n f(0+0i)="); complex_print(f(complex_init(0,0),roots.grad, poly)); printf("df(0+0i)="); complex_print(df(complex_init(0,0),roots.grad, poly)); tries=0; do{ tries++; theta=drand48()*2*M_PI; x=radius*cos(theta); y=radius*sin(theta); z=complex_init(x,y); for(i=0;i<=nit;i++){ fz = f(z,roots.grad,poly); dfz=df(z,roots.grad,poly); if(complex_abs(dfz)<ee){ break; } w=z; z=complex_sub(z,complex_div(fz,dfz)); if(complex_abs(complex_sub(z,w))<=eps){ process_root(z,&roots,eps); break; } } }while(roots.nor<roots.grad); printf("\nTook %d tries to get all %d roots\n",tries,roots.grad); printf("\nZeroes and their images:\n\n"); for(i=0;i<roots.grad;i++){ printf("Root Z%d=%+lf %+lfi \tf(z%d)=",i+1,roots.root[i].x,roots.root[i].y,i+1); complex_print(f(roots.root[i],roots.grad, poly)); } return EXIT_SUCCESS; }