Home > Back-end >  Novice inquired, Taylor expansion input more than 16 will be beyond the scope of cos
Novice inquired, Taylor expansion input more than 16 will be beyond the scope of cos

Time:12-07

Taylor expansion input more than 16 will be beyond the scope of cos, pure novice, overflow or what problem is data
Public static void main (String [] args) {

If (args. The length==0) {
System. The out. Println (" ERROR ");
return;
}
The else {
Double n=0.0;
Double Max=20.0;
Double a=1.0;
Double sum=0.0;
Double cosine=0.0;
Double z=double. ParseDouble (args [0]).
For (n=0.0; n<=Max; N++) {
Double b=1.0;
Double x=1.0;
If (n==0.0) {
A=1.0;
X=1.0;
B=1.0;
}
The else {
{if (n % 2==0)
A=1.0;
}
The else {
A=1.0;
}
For (double t=1.0; t<=2 * n; T++) {
B=b * t;
X=x * z;
}
}
Cos=(a/b) * x;
Sum=sum + cos;
Double sum1=(long) (sum * 100)/100.0;
If (n + 1 & gt; Max) {
System. The out. Println (sum1);
}
}
}

}
}

To code a Taylor expansion cosine values (keep two), but no more than 16 in input data is accurate, after more than 16 inaccurate start
the condition of the20
Cos (x)=?((1) ^ n/(2 n)!) * x ^ 2 n
N=0
  • Related