Java数学方程求解器[非标准方程]
我需要一个java方法,它返回一个方程的解,这个方程没有代码,如下所示:Java数学方程求解器[非标准方程],java,algorithm,math,equation,Java,Algorithm,Math,Equation,我需要一个java方法,它返回一个方程的解,这个方程没有代码,如下所示: 获取一个数字(Z) 以弧度表示的角度(C) 然后求出X的值,这是该方程的解: a = Integer( z*cos(c) ) // temp must be integer //now we have the value of a // we put it in b b = a //now we look for the value of x that solves this equation b =? Integer(
a = Integer( z*cos(c) ) // temp must be integer
//now we have the value of a
// we put it in b
b = a
//now we look for the value of x that solves this equation
b =? Integer( X/cos(C) ) // X also must be integer
X = ?? // we must get X the solves the equation above
例如:考虑
Z = 15
C = 140 // full angles will be casted ..it will be rooted to ~-0.0629*PI
temp = Integer( 15*cos(140) // -2.96 )
temp <-- -2 //after parsing to integer
-2 = Integer ( X )/cos(140)
what is X ?
之后,变量x将存储在一个文件中。。。
然后,当文件打开时,此变量x将通过此函数返回给z:
int returning(int x, int c){
int z = (int) ( x/Math.cos(c) );
return z;
}
实际上,方程组有无穷多个解。说
temp=2
。你写道:
2 = Integer ( ( X )/cos(140) )
如果我们从您的帖子中为
2.0范围内的所有实数取Integer()
temp = Integer( 15*cos(140) // -2.96 )
Find X such that
temp = Integer ( X/cos(140) )
我们可以在不进行整数转换的情况下解决X的问题
X = 15 / cos^2(140)
或者,一般来说
X = Z / cos^2(C)
这将给出X的精确解;如果出于其他目的需要,您可以应用integer中间要求
按操作评论更新
在X
、temp
和Z
之间有一个定义的数学关系。截断中间结果会破坏某些关系。简言之,如果将X
限制为整数,则无法保证在应用逆运算时得到的是确切的Z
特别是,你有一个超越函数cos;您不能指定它是整数temp
和X
或X
和Z
的比率。对于已知的有理数,cos
确实存在点解,但非常少
如果我误解了这个问题——我意识到我们有一些翻译问题——那么请更新您的问题以指定正确的问题。修复您编写的方程temp=Integer(z*cos(c))temp=Integer(X/cos(c))
方程的奇数定义。你是说整数(Z*cos(C))=整数(X/cos(C))
?Integer
也是四舍五入还是向下四舍五入?调试时会看到什么?它在你的循环中做正确的数学运算吗?它是收敛到某个值还是振荡?有整数解吗?调试是这里的一个重要步骤…不,它不是给我调试的错误,但很多时候它找不到一个整数来解方程谢谢,但像这样,我不能保证如果我取了x并做了:x/Math.cos(c)它并不总是等于zi,我添加了这个down的目的是的,当它是//integer时你是正确的((X)/cos(140))//但我现在写错了,它是固定的:整数(X)/cos(140)。这个问题解决了,因为这是不可能的,谢谢你的时间:)对不起,但这没有帮助,X必须是整数,正如上面所说的,当返回它时,它必须给我们返回的数字zyes,这也是我所想的。。。在某些情况下,将结果限制为整数可能不会使方程成为可能。。。很遗憾..我必须改变如何加密x值
int Rounding(int z, int c){
int test = ( z*Math.cos(c) );
int x = (int) ( test*Math.cos(c) );
return x;
}
temp = Integer( 15*cos(140) // -2.96 )
Find X such that
temp = Integer ( X/cos(140) )
X = 15 / cos^2(140)
X = Z / cos^2(C)