求余弦值代码java 余弦值算法

请问JAVA中应该用哪一条语句实现 已知正玄或余玄函数,求角度java.lang.Math类中求余弦值代码java的如下方法均可:
public static double acos(double a)返回角的反余弦求余弦值代码java,范围在 0.0 到 pi 之间求余弦值代码java;
public static double asin(double a)返回角的反正弦求余弦值代码java,范围在 -pi/2 到 pi/2 之间求余弦值代码java;
public static double atan(double a)返回角的反正切,范围在 -pi/2 到 pi/2 之间 。
直接调用Math.acos(正玄值),然后乘以(180/pi) 转化成角度 。
java求任意角度的角的正弦和余弦的值的方法!并且写一个可以求出n到m之间的随机整数的方法 。java.lang.Math类
Math中的方法
double b;
b=sin(double a)返回a角的三角正弦 。
b=cos(double a)返回a角的三角余弦 。望采纳,谢谢 。
汇编编程求一弧度的正弦或余弦?你好,三角函数运算指令为:
SIN指令
sin double sin(double x); 计算x弧度的正弦值
asin double asin(double x); 计算绝对值不大于1的浮点数的反正弦值
该指令从运算栈中弹出一个操作数,计算它(弧度)的三角正弦值,并将结果压入运算栈 。
CON指令
cos double cos(double x); 计算x弧度的余弦值
acos double acos(double x); 计算绝对值不大于1的浮点数的反余弦值
该指令从运算栈中弹出一个操作数 , 计算它(弧度)的三角余弦值,并将结果压入运算栈 。
举例 , 可以模仿以下例子来计算即可~
#include iostream
#include iomanip
#include cstdlib
#include cstring
#include cctype
#include cmath
using namespace std;
const char Tab=0x9;
const intDIGIT=1;
double fun(double x,char op[],int *iop)
{
while(op[*iop-1]32) //本行使得函数嵌套调用时不必加括号
//如 arc sin(sin(1.234)) 只需键入arc sin sin 1.234Enter
switch(op[*iop-1])
{
case7: x=sin(x);(*iop)--;break;
case8: x=cos(x);(*iop)--;break;
case9: x=tan(x);(*iop)--;break;
case 10: x=sqrt(x); (*iop)--;break;
case 11: x=asin(x); (*iop)--;break;
case 12: x=acos(x); (*iop)--;break;
case 13: x=atan(x); (*iop)--;break;
case 14: x=log10(x);(*iop)--;break;
case 15: x=log(x);(*iop)--;break;
case 16: x=exp(x);(*iop)--;break;
}
return x;
}
double calc(char *expr,char **addr)
{
static deep; //递归深度
static char *fname[]={ "sin","cos","tan","sqrt",
"arcsin","arccos","arctan","lg","ln","exp",NULL};
double ST[10]={0.0}; //数字栈
char op[10]={' '}; //运算符栈
char c,*rexp,*pp,*pf;
int ist=1,iop=1,last;
if(!deep)
{
pp=pf=expr;
do
{
c = *pp;
if(c!=' ' c!=Tab)
*pf= c;
}
while(c!='\0');
}
pp=expr;
if((c=*pp)=='-'||c==' ')
{
op[0] = c;
pp;
}
last = !DIGIT;
while((c=*pp)!='\0')
{
if(c=='(')//左圆括弧
{
deep;
ST[ist]=calc(pp,addr);
deep--;
ST[ist-1]=fun(ST[ist-1],op,iop);
pp = *addr;
last = DIGIT;
if(*pp == '('||isalpha(*pp)strnicmp(pp,"Pi",2))
{////目的是:当右圆括弧的
op[iop]='*'; ////右恻为左圆括弧或函数
last = !DIGIT; ////名字时,默认其为乘法
c = op[--iop]; /////////////////////////////
goto operate ; /////////////////////////////
}
}
else if(c==')')//右圆括弧
{
pp;
break;
}
else if(isalpha(c))
{
if(!strnicmp(pp,"Pi",2))
{
if(last==DIGIT){cout "π左侧遇)" endl;exit(1);}
ST[ist]=3.14159265358979323846;
ST[ist-1]=fun(ST[ist-1],op,iop);
pp= 2;
last = DIGIT;
if(!strnicmp(pp,"Pi",2)){cout "两个π相连" endl;exit(2);}
if(*pp=='('){cout "π右侧遇(" endl;exit(3);}
}
else
{
for(int i=0; (pf=fname[i])!=NULL; i)
if(!strnicmp(pp,pf,strlen(pf)))break;
if(pf!=NULL)
{
op[iop] = 07 i;
pp= strlen(pf);
}
else {cout "陌生函数名" endl;exit(4);}
}
}
else if(c==' '||c=='-'||c=='*'||c=='/'||c=='^')
{
char cc;
if(last != DIGIT){cout "运算符粘连" endl;exit(5);}
pp;
if(c==' '||c=='-')
{
do
{
cc = op[--iop];
--ist;
switch(cc)
{
case ' ':ST[ist-1]= ST[ist];break;
case '-':ST[ist-1] -= ST[ist];break;
case '*':ST[ist-1] *= ST[ist];break;
case '/':ST[ist-1] /= ST[ist];break;
case '^':ST[ist-1] = pow(ST[ist-1],ST[ist]);break;
}
}
while(iop);
op[iop] = c;
}
else if(c=='*'||c=='/')
{
operate:cc = op[iop-1];
if(cc==' '||cc=='-')
{
op[iop] = c;
}
else
{
--ist;
op[iop-1] = c;
switch(cc)
{
case '*':ST[ist-1] *= ST[ist];break;
case '/':ST[ist-1] /= ST[ist];break;
case '^':ST[ist-1] = pow(ST[ist-1],ST[ist]);break;
}
}
}
else
{
cc = op[iop-1];
if(cc=='^'){cout "乘幂符连用" endl;exit(6);}
op[iop] = c;
}
last = !DIGIT;
}
else
{
if(last == DIGIT){cout "两数字粘连" endl;exit(7);}
ST[ist]=strtod(pp,rexp);
ST[ist-1]=fun(ST[ist-1],op,iop);
if(pp == rexp){cout "非法字符" endl;exit(8);}
pp = rexp;
last = DIGIT;
if(*pp == '('||isalpha(*pp))
【求余弦值代码java 余弦值算法】{
op[iop]='*';
last = !DIGIT;
c = op[--iop]; /////////////////////////////
goto operate ; /////////////////////////////
}
}
}
*addr=pp;
if(iop=ist){cout "表达式有误" endl;exit(9);}
while(iop)
{
--ist;
switch(op[--iop])
{
case ' ':ST[ist-1]= ST[ist];break;
case '-':ST[ist-1] -= ST[ist];break;
case '*':ST[ist-1] *= ST[ist];break;
case '/':ST[ist-1] /= ST[ist];break;
case '^':ST[ist-1] = pow(ST[ist-1],ST[ist]);break;
}
}
return ST[0];
}
int main()
{
char s[128],*end;
system("chcp 936"); //中文代码页
while(1)
{
cout"请输入表达式:";
cin.getline(s,128);
coutsetprecision(17)calc(s,end)endl;
}
return 0;
}
JAVA中如何进行正弦和余弦的计算java.lang.Math类
Math中的方法
double b;
b=sin(double a)返回a角的三角正弦 。
b=cos(double a)返回a角的三角余弦 。
求余弦值代码java的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于余弦值算法、求余弦值代码java的信息别忘了在本站进行查找喔 。

    推荐阅读