用java代码泰勒公式 泰勒公式怎么代数

java编程 泰勒级数 x-x^3/3! x^5/5! ...//请采纳用java代码泰勒公式!
package com.cainiaoqi;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
double x = 0;
Scanner in = new Scanner(System.in);
System.out.print("请输入x:");
x = in.nextDouble();
System.out.println("sin(" x ") = " calcsin(x));
}
static double calcsin(double x) {
double result = 0;
int temp = 0;
while((Math.pow(x,2*temp 1)/jiecheng(2*temp 1))1.0E-8) {
result= (Math.pow(x,2*temp 1)/jiecheng(2*temp 1))*Math.pow(-1, temp);
temp;
//System.out.print("第" temp "次迭代用java代码泰勒公式!" );
//System.out.println(result);
}
return result;
}
static int jiecheng(int x) {
if(x==1)
return 1;
else
return jiecheng(x-1)*x;
}
}
e的近似值精确到10的-6次方的JAVA程序怎么写?使用泰勒公式求e
e=1 1/1! 1/2! 1/3! ......
看看这个行不用java代码泰勒公式?
class EDeJinSiZhi
{
Public static void main(String args[])
{
double e=1;
double jc=1;
int i=1;
while(1/jc=1e-6)
{
e=e 1/jc;
i;
jc=jc*i;
}
System.out.println("The Value of e is " e);
System.out.println("Loop completed!");
}
设计一个java程序,求泰勒公式COSx=1-x2/2! x4/4!-x6/6! x8/8!..import java.util.Scanner;
public class Test{
public static void main(String[] args){
System.out.print("输入x:");
Scanner in=new Scanner(System.in);
double x=in.nextDouble();
System.out.println("cos" x "=" Taylor(x));
}//COSx=1-x2/2用java代码泰勒公式! x4/4用java代码泰勒公式!-x6/6用java代码泰勒公式! x8/8用java代码泰勒公式!..
public static double Taylor(double x){
int i,k;
long fac=1;//阶乘
double n=1,y=1,sum=1;
for(i=2;(Math.abs(y))=1e-8;i =2)
{ n=n*(-1);
for(k=1;k=i;k)
fac=fac*k;
y=Math.pow(x, i)*n/fac;
sum =y;
fac=1;
}
return sum;
【用java代码泰勒公式 泰勒公式怎么代数】 }
}
1 (1 5) (1 5 8) ……(3*n-1)用Java实现?分析表达式规律:
当 n=1 时 , 表达式为 1 ;
当 n=2 时,表达式为 1 (1 (3*2-1))=1 (1 5);
当 n=3 时,表达式为 1 (1 5) (1 5 (3*2-1))=1 (1 5) (1 5 8);
第一个数为 1 ,从第二数开始,该数为(前一个数 (3*n-1) (n=2)),然后再累加所有数 。
参考代码如下:
public class MathExp {
public static void main(String[] args) {
System.out.println(exp(3));
}
public static int exp(int n){
if(n0) return 0;
int res = 0; // 累计总和
int num = 1; // 第一个数为 1,从第二个数开始是 num3*n-1
for(int i = 1; i = n; i){
if(i == 1){
res = num;
}else {
num= 3 * i - 1; // 第 n 个 数
res= num; // 累加第 n 个 数
}
}
return res;
}
}
java计算机程序中sin如何实现根据泰勒公式:
sin(x)=x-x^3/3! x^5/5! …… (-1)^(n-1)*x^(2n-1)/(2n-1)
可以使用迭代法来求sin了,如果需要精度计算,则需要bigdecimal工具来保存精确的浮点数
编写一个Java程序,从键盘输入x , 利用台劳公式计算COS(x)的值,并输出之是泰勒公式吧,给你参考
#includestdio.h
double getEx(double x,int n){
double temp=1;
for(int i=0;in;i){
temp*=x;
}
return temp;
}
double getJiecheng(int n){
double temp=n;
for(int i=n-1;i=1;i--){
temp*=i;
}
if(n/2%2==0)
return temp;
else
return -1*temp;
}
double getfabs(double t){
if(t=0)
return t;
else
return -1*t;
}
void main(){
const double E=1e-6;
double x,t,ans=1;
int n=2;
x=0.5
do{
t=getEx(x,n)/getJiecheng(n);
ans =t;
n =2;
if(getfabs(t)=E){
break;
}
}while(true);
printf("cos(%f)=%f\n",x,ans);
}
用java代码泰勒公式的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于泰勒公式怎么代数、用java代码泰勒公式的信息别忘了在本站进行查找喔 。

    推荐阅读