Vous êtes sur la page 1sur 7

Submission I, Capter 1, 2(1,2)

Tanay Bansal
12PH20034
January 21, 2015

The Problem

We are asked to calculate- 1)The true sine value (say y) of a given number
x. 2)The approximated value(saysineapp) upto certain terms (say m) in
sine series. 3)Calculate fractional difference say delta = (sineapp-y)/y.

Method

1)We take the the value of x and m using scanf function. 2)Calculate true
sin(x) using sin function included in math.h library. 3)We implement two
statements inside a for loop to calculate the approximated sine value, sineapp.

2.1

The program

#include <stdio.h>
#include <math.h>
int main()
{
double x,z;
int m,n;
double delta;
double sineapp=0;
double fac=1;
printf("give the value of x in degrees\n");
scanf("%lf",&x);
x=x*3.141592653589/180;
z=sin(x);
printf("the true value of sin(x) is %lf\n",z);
printf("give the integer value of m\n");
scanf("%d",&m);

for(n=0;n<=m;n++)
{
sineapp+=(double)pow(-1,n)*pow(x,(2*n)+1)/fac;
fac=fac*(2*(n+1))*(2*(n+1)+1);
}
printf("\nthe value of sineapp is %lf \n", sineapp);

delta=(sineapp-z)/z;
printf("the value of delta is %e", delta);
return 0;
}

2.2

Inputs

Here we have given an inputs as- x, which is the value over which sin will
operate z, which is , which says ........

2.3

Outputs

>gcc -o sinx sin.c


>./sinx
give the value of x in degrees
1
the true value of sin(x) is ..
give the integer value of m
0
the value of sineapp is ..
the value of delta is ..
>gcc -o sinx sin.c
>./sinx
give the value of x in degrees
1
the true value of sin(x) is ..
give the integer value of m

1
the value of sineapp is ..
the value of delta is ..
>gcc -o sinx sin.c
>./sinx
give the value of x in degrees
1
the true value of sin(x) is ..
give the integer value of m
2
the value of sineapp is ..
the value of delta is ..
>gcc -o sinx sin.c
>./sinx
give the value of x in degrees
1
the true value of sin(x) is ..
give the integer value of m
3
the value of sineapp is ..
the value of delta is ..
>gcc -o sinx sin.c
>./sinx
give the value of x in degrees
1
the true value of sin(x) is ..
give the integer value of m
4
the value of sineapp is ..
the value of delta is ..
>gcc -o sinx sin.c
>./sinx
give the value of x in degrees
1

the true value of sin(x) is ..


give the integer value of m
5
the value of sineapp is ..
the value of delta is ..
>gcc -o sinx sin.c
>./sinx
give the value of x in degrees
10
the true value of sin(x) is ..
give the integer value of m
0
the value of sineapp is ..
the value of delta is ..
>gcc -o sinx sin.c
>./sinx
give the value of x in degrees
10
the true value of sin(x) is ..
give the integer value of m
1
the value of sineapp is ..
the value of delta is ..
>gcc -o sinx sin.c
>./sinx
give the value of x in degrees
10
the true value of sin(x) is ..
give the integer value of m
2
the value of sineapp is ..
the value of delta is ..
>gcc -o sinx sin.c

>./sinx
give the value of x in degrees
10
the true value of sin(x) is ..
give the integer value of m
3
the value of sineapp is ..
the value of delta is ..
>gcc -o sinx sin.c
>./sinx
give the value of x in degrees
10
the true value of sin(x) is ..
give the integer value of m
4
the value of sineapp is ..
the value of delta is ..
>gcc -o sinx sin.c
>./sinx
give the value of x in degrees
10
the true value of sin(x) is ..
give the integer value of m
5
the value of sineapp is ..
the value of delta is ..
>gcc -o sinx sin.c
>./sinx
give the value of x in degrees
30
the true value of sin(x) is ..
give the integer value of m
0
the value of sineapp is ..

the value of delta is ..


>gcc -o sinx sin.c
>./sinx
give the value of x in degrees
30
the true value of sin(x) is ..
give the integer value of m
1
the value of sineapp is ..
the value of delta is ..
>gcc -o sinx sin.c
>./sinx
give the value of x in degrees
30
the true value of sin(x) is ..
give the integer value of m
2
the value of sineapp is ..
the value of delta is ..
>gcc -o sinx sin.c
>./sinx
give the value of x in degrees
30
the true value of sin(x) is ..
give the integer value of m
3
the value of sineapp is ..
the value of delta is ..
>gcc -o sinx sin.c
>./sinx
give the value of x in degrees
30
the true value of sin(x) is ..
give the integer value of m

4
the value of sineapp is ..
the value of delta is ..
>gcc -o sinx sin.c
>./sinx
give the value of x in degrees
30
the true value of sin(x) is ..
give the integer value of m
5
the value of sineapp is ..
the value of delta is ..

Results

The equation used for the approximate value of the sine series is :
(1)n x2n+1
sinapp = m
0
(2n+1)!

Vous aimerez peut-être aussi