Sign in to follow this  
Cornel Iulian

[C] Dezvoltare serie Taylor pentru sin(x) = ...

1 post in this topic

Cerinta: Stiind ca dezvoltarea in serie a functiei sin(x) este:

sin(x) = x/1!-x^3/3!+x^5/5!-...

sa se calculeze valoarea aproximativa a lui sin(x), pentru un x preluat de la consola, cu o eroare mai mica in modul decat un eps precizat.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
	int k;
	double x,eps,t,sin_aprox;
	printf("Sa se introduca doua valori reale, x si eps:\n");
	if(scanf("%lf%lf",&x,&eps)!=2)
	{
		printf("Date eronate");
		exit(1);
	}
	sin_aprox=0;
	k=1;
	t=x;
	while(fabs(t)>=eps)
	{
		sin_aprox+=t;
		t*=(-x*x)/((2*k)*(2*k+1));
		k+=1;
	}
	
	printf("sin_aprox(%g)= %g\nsin(%g)= %g",x,sin_aprox,x,sin(x));
	return 0;
}

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this