Esempio n. 1
0
int tang(int argc, char * argv[])
{
 double x;
 unsigned int n,i;
 char * err;
 if (argc >5) 
    {
     fprintf(stderr, "ERROR bolo zadanych vela argumentov pre funkciu --tan \n");// ak je zadanych viac argumentov ako je dane pre funkciu vypise chybu 
     return EXIT_FAILURE;
    }
 x = strtod(argv[2],&err);   //osterenie chybneho vstupu
 if (err == argv[2])
    {
     fprintf(stderr,"ERROR zaddana zla hodnota\n");
     return EXIT_FAILURE;
    }
 n = atoi(argv[4]); //posledny prvok rozsahu
 i= atoi(argv[3]);// prvy prvok rozsahu
 if (x>1.4)
    {
     fprintf(stderr, "ERROR zadany zly rozsah parametrov\n");// ak je zadany zly rozsah parametrov tak vypise chybove hlasenie 
     return EXIT_FAILURE;
    }
 if (i>n || n >14)
    {
     fprintf(stderr, "ERROR zadany zly rozsah\n"); // ak je zadany zly rozsah tak vypise chybove hlasenie 
     return EXIT_FAILURE;
    }
 for(;i<=n;i++)
    printf ("%d %e %e %e %e %e\n",i , tan(x), taylor_tan(x,i-1), MYABS(tan(x) - taylor_tan(x,i-1) ) , cfrac_tan(x,i),MYABS((tan(x) - cfrac_tan(x,i)) )); // vypis funkcie --tan
 return EXIT_SUCCESS;
}
Esempio n. 2
0
File: main.c Progetto: Glooby5/proj2
/**
 * Spocita tangens nekolika zpusoby a vypocita absolutni chyby
 * @param val Hodnoty pro vypocet
 */
void calculateTan(TValue val)
{
    double tan_lib = tan(val.A);
    double tan_taylor;
    double tan_cfrac;
    double te;
    double ce;

    for (unsigned int i = val.N; i <= val.M; i++)
    {
        tan_taylor = taylor_tan(val.A, i);
        tan_cfrac = cfrac_tan(val.A, i);

        te = my_fabs(tan_taylor - tan_lib);
        ce = my_fabs(tan_cfrac - tan_lib);

        printf("%d %e %e %e %e %e\n", i, tan_lib, tan_taylor, te, tan_cfrac, ce);
    }
}
Esempio n. 3
0
int main(int argc, char **argv)
{
	double x, y;
	unsigned int n, p, D;
	mpfr_t R, X;
	char sf[50];
	FILE *in;
	
	if(argc > 1)
	{
		switch(argv[1][0])
		{
			case 'a':
				if(argc == 5 && 
				   sscanf(argv[2], "%lf", &x) == 1 &&
				   sscanf(argv[3], "%u" , &n) == 1 &&
				   sscanf(argv[4], "%u" , &D) == 1)
					printf("Cos(%.*lf) = %.*lf\n",
							d(D), x, D, taylor_cos(x, n));
				else
					printf("Usage: %s a <x=value for Cos(x)> <n> "
						   "<D=Number of digits to display>\n",

							argv[0]);
				break;
			 
			case 'b':
				if(argc == 5 && 
				   sscanf(argv[2], "%lf", &x) == 1 &&
				   sscanf(argv[3], "%u" , &n) == 1 &&
				   sscanf(argv[4], "%u" , &D) == 1)
					printf("Sin(%.*lf) = %.*lf\n",
							d(D), x, D, taylor_sin(x, n));
				else
					printf("Usage: %s b <x=value for Sin(x)> <n> "
						   "<D=Number of digits to display>\n",

							argv[0]);
				break;

			case 'c':
				if(argc == 5 && 
				   sscanf(argv[2], "%lf", &x) == 1 &&
				   sscanf(argv[3], "%u" , &n) == 1 &&
				   sscanf(argv[4], "%u" , &D) == 1)
					printf("Tan(%.*lf) = %.*lf\n",
							d(D), x, D, taylor_tan(x, n));
				else
					printf("Usage: %s a <x=value for Tan(x)> <n> "
						   "<D=Number of digits to display>\n",

							argv[0]);
				break;
			
			case 'd':
				if(argc == 6 && 
				   sscanf(argv[3], "%u", &D) == 1 &&
				   sscanf(argv[4], "%u", &n) == 1 &&
				   sscanf(argv[5], "%u", &p) == 1)
				{
					mpfr_set_default_prec(p);
					INIT_CONSTANTS
					if (mpfr_init_set_str(X, argv[2], 10, MPFR_RNDN) == 0)
					{
						mpfr_init(R);

						sprintf(sf, "cos(%%.%uRNf) =~\n\t%%.%uRNf\n",
							d(D), D);
						
						mpfr_taylor_cos(R, X, n);
						mpfr_printf(sf, X, R);
					}
					else
						printf("Usage: %s d <x=value for Cos(x)> "
							   "<D=Number of digits to display> "
							   "<n> <p=bits of precision to use>\n",
							   argv[0]);
				}
				else
					printf("Usage: %s d <x=value for Cos(x)> "
						   "<D=Number of digits to display> "
						   "<n> <p=bits of precision to use>\n",
						   argv[0]);
				break;
			
			case 'e':
				if(argc == 6 && 
				   sscanf(argv[3], "%u", &D) == 1 &&
				   sscanf(argv[4], "%u", &n) == 1 &&
				   sscanf(argv[5], "%u", &p) == 1)
				{
					mpfr_set_default_prec(p);
					INIT_CONSTANTS
					if (mpfr_init_set_str(X, argv[2], 10, MPFR_RNDN) == 0)
					{
						mpfr_init(R);

						sprintf(sf, "sin(%%.%uRNf) =~\n\t%%.%uRNf\n",
							d(D), D);
						
						mpfr_taylor_sin(R, X, n);
						mpfr_printf(sf, X, R);
					}
					else
						printf("Usage: %s d <x=value for Sin(x)> "
							   "<D=Number of digits to display> "
							   "<n> <p=bits of precision to use>\n",
							   argv[0]);
				}