Ejemplo n.º 1
0
// Iterates the function juliamap
int iterate(COMPLEX z, COMPLEX *c){
  unsigned long int i, j, n;
  n=0;
  for(;;){
    z = juliamap(&z, c);
    n=n+1;
    if(square_mod(&z)>4){
      return n;
    }
    else if(n>=MAXITER){
      return 0;
    }
  }
}
Ejemplo n.º 2
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);
}
Ejemplo n.º 3
0
/* It returns the result of the desirable function among the functions defined above (mult2, square, add2, juliamap)*/
COMPLEX get_result(char *name, COMPLEX *a, COMPLEX *b){
  COMPLEX c;
  if(strcmp("mult2",name)==0){
    c=mult2(a,b);
  }
  else if(strcmp("square",name)==0){
    c=square(a);
  }
  else if(strcmp("add2",name)==0){
    c=add2(a,b);
  }
  else if(strcmp("juliamap",name)==0){
    c=juliamap(a,b);
  }
  return c;
}
Ejemplo n.º 4
0
/*    method calculates z^2 + c for every (z,c) given
 *   loops until the max number of iterations is reaches
 *     OR the magnitude is greater than 2*/
int cplane::iterate(std::complex<long double> *z, std::complex<long double> *c)
{
        std::complex<long double> y = *z;
        unsigned int out;

        for (out = 1; out < MAXITER; out++)
        {

                if (std::abs(y) > 2)                                        
                   {return out;}
       		 
                y = juliamap(&y, c);
	}

        return 0;
}
Ejemplo n.º 5
0
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");
}
Ejemplo n.º 6
0
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" );

}
Ejemplo n.º 7
0
int main(int argc, char **argv)
{
/************************************************************************************
* Function: int main()
* Input : xmin, xmax, ymin, ymax, xpoints, ypoints, creal, and cimag
* Output : Returns 0 on success
* Procedure: Performs operations on complex numbers and prints results.
************************************************************************************/

// check for input parameters
if ( argc != 9) {
   printf ( " The program is expecting 8 input parameters, you entered :%d \n", argc -1);
   return(-1);
}

// Initialize all the parameters
CPLANE cp;
int MAXITER=256;
char *e;
INDEX rows,cols;
complex c, z, v;
VALUE xmin  = strtold(argv[1], &e);
VALUE xmax = strtold(argv[2], &e);
VALUE ymin = strtold(argv[3], &e);
VALUE ymax = strtold(argv[4], &e);
INDEX xpoints = strtoul(argv[5], &e, 0);
INDEX ypoints = strtoul(argv[6], &e,0);
VALUE creal = strtold(argv[7], &e);
VALUE cimag = strtold(argv[8], &e);
c.x = creal;
c.y = cimag;

// create a new plane
cp = new_cplane(xmin,xmax,ymin,ymax,xpoints,ypoints);
// print_matrix(&cp);

// Traverse through the plane
  for(rows=0; rows<ypoints; rows++) {
    for(cols=0; cols<xpoints; cols++) {
    v = get ( &cp, rows,cols); 
    z.x = v.x;
    z.y = v.y;
    int m = 0;
    while (1) {
          // printf("The absolute values is %d \n", abs(z.x+z.y));
          z = juliamap(z,c);
          m = ++m;
          if (abs(z.x+z.y) > 2) {
             printf("%Lf,%Lf,%d \n", v.x, v.y, m);
             break;
           }
           else if ( m >= MAXITER) {
             printf("%Lf,%Lf,%d \n", v.x, v.y, 0);
             break;
           }
      } /* end of while loop */
    } /* end of cols */
  } /* end of rows */

// clean up memory
delete_cplane(cp);
return 0;
}