在VB.net中计算三角函数正弦值的问题 [英] Problem in caculating Trigonometric Sine values in VB.net
问题描述
如何计算vb.net中的正弦值???
值应介于-1和1之间。
我将代码编写如下vb.net
How to calculate the sine values in vb.net???
The values should be lie between -1 and 1.
I write the code as follows in vb.net
Label1.Text= Math.Sin(Math.PI)
点击按钮,结果显示在Label1上:1.2246063638223
问题是值应该介于-1和1之间。但是在vb.net中,值大于1,如上所述。当我在Matlab中检查相同的正弦值时:
On button click, the result is shown on Label1 is : 1.2246063638223
The problem is that the values should lie between -1 and 1. But in vb.net, values are greater than 1 like above. When I check the same above sine value in Matlab:
sin(pi)
结果是:1.2246e-016
介于-1和1之间
当我在计算器上检查相同时。再次,值介于-1和1之间,然后如何在vb.net中解决我的问题。
The result is: 1.2246e-016
Which is between -1 and 1
When i check the same on calculator. again the value is between -1 and 1, then how to resolve my problem in vb.net.
推荐答案
你实际看到的答案是1.22460635382238 E-16
您可能会发现您的标签不够宽并且AutoSize = False
但是,.Net Math.Sin期望角度是弧度,tyour Math.PI代表什么?
转换是[角度度] *(Math.PI / 180)=弧度。
Mike
The answer you''re actually seeing is 1.22460635382238 E-16
You might find your label is not wide enough and has AutoSize = False
However, .Net Math.Sin expects the angle to be in radians, what does tyour Math.PI represent?
The conversion is [angle in degrees] * (Math.PI / 180) = radians.
Mike
解决方案1和2是正确的。在大多数情况下,您不需要以默认格式输出值。
首先,为字符串属性分配一个double值。这样的赋值在.NET中没有任何意义,但是VB.NET通过赋予非double值来提供自动解决方法,但是double.ToString()
,这实际上是一个坏事;如果发出编译错误会更好,因为它通常已经完成。
你应该总是使用ToString
,它还允许您在此函数的其他形式中提供两者的文化,格式字符串。请参阅: http://msdn.microsoft.com/en-us/library/system .double.tostring.aspx [ ^ ]。
对于格式字符串及其效果,请参阅:
http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/0c899ak8.aspx [ ^ ]。
-SA
The Solution 1 and 2 are correct. In most cases, you don''t need to output value in its default format.
First of all, you assign a double value to a string property. Such assignment makes no sense in .NET, but VB.NET provides "automatic" work-around by assigning not double value, butdouble.ToString()
, which is actually a bad thing; it would be much better it if issued a compilation error instead, as it is normally done.
You should always useToString
, which also allows you, in other forms of this function, to provide culture, format string, of both. Please see: http://msdn.microsoft.com/en-us/library/system.double.tostring.aspx[^].
For format strings and their effect, please see:
http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx[^],
http://msdn.microsoft.com/en-us/library/0c899ak8.aspx[^].
—SA
您的标签太短 - 实际上显示的是1.2240635382238E-16
Your label is too short - it is actually displaying 1.2240635382238E-16
这篇关于在VB.net中计算三角函数正弦值的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!