ineedtocreateamethodwhichiscalleddoublesin(doublenumber)anduserecursivefunction.iuseTaylorseriesapproximationandhereisthecodepublicdoublefactorial(intnumber)//thisisthere...
i need to create a method which is called double sin(double number) and use recursive function . i use Taylor series approximation and here is the code public double factorial(int number) // this is the recurision of factorial
{
if(number==0) //0!=1
{
return 1.0;
}
return (double)number*factorial(number-1);
}
public double sin(double number) // this is the method of sin(x)
{
double sinAns=0;
double sum=0;
for(int i=1;i<=9;i=i+4)
{
sum=pow(number,i)-pow(number,(i+2))/factorial(i+2);
sinAns=sum+sinAns;
}
return sinAns;
}
when i call the method, it returns back
public double factorial(int number) // this is the recurision of factorial
{
if(number==0) //0!=1
{
return 1.0;
}
return (double)number*factorial(number-1);
}
public double sin(double number) // this is the method of sin(x)
{
double sinAns=0;
double sum=0;
for(int i=1;i<=9;i=i+4)
{
sum=pow(number,i)-pow(number,(i+2))/factorial(i+2);
sinAns=sum+sinAns;
}
return sinAns;
}
i am a early learner, and i do not know why the reason is
i expect somebody can help me
xiexie
展开