gpt4 book ai didi

java - 余弦定理JAVA

转载 作者:太空宇宙 更新时间:2023-11-04 09:22:55 25 4
gpt4 key购买 nike

我正在尝试创建一种余弦定律的方法,但惨败使用

a=8

b = 9

c = 5

输出应为0.80693439407

有了这个,我得到了 0.8546475409378381 作为输出

public  double cos(double a, double b, double c)
{
double ang=(Math.pow(a,2))-(Math.pow(b,2)-Math.pow(c,2))/(2*b*c);
return Math.cos(ang);
}

有人可以帮我用这个方法吗?

最佳答案

Wrong formula .

// TODO: Special cases?  What if a or b are zero?
// Returned angle is in radians, not degrees.
public double getAngle(double a, double b, double c) {
return Math.acos((a*a + b*b - c*c)/(2.0*a*b));
}

关于java - 余弦定理JAVA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58089378/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com