使用pi = x * sin(180 / x)计算PI的值

时间:2019-01-15 03:55:52

标签: ruby math pi

我在使用public class WSAdapter { /*@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); }*/ public class SendPostsRequest extends AsyncTask<String, String, String> { TextView postsSect; // Add a pre-execute thing HttpURLConnection urlConnection; private WeakReference<Activity> mPostReference; /*public SendPostsRequest(Activity activity){ mPostReference = new WeakReference<Activity>(activity); }*/ @Override protected String doInBackground(String... params) { StringBuilder result = new StringBuilder(); try { urlConnection = (HttpURLConnection) new URL(params[0]).openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.connect(); InputStream in = new BufferedInputStream(urlConnection.getInputStream()); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line; while ((line = reader.readLine()) != null) { result.append(line); } }catch( Exception e) { e.printStackTrace(); } /*finally { urlConnection.disconnect(); }*/ return result.toString(); } @Override protected void onPostExecute(String result) { // expecting a response code fro my server upon receiving the POST data Log.e("TAG", result); Posts.PostsDetails postsHelper = new Posts().new PostsDetails(); // For posts try { JSONArray pJObjArray = new JSONArray(result); // algorithm for parsing the JSONArray from the Django REST API for (int i = 0; i < pJObjArray.length(); i++) { // puts the current iterated JSON object from the array to another temporary object JSONObject pJObj_data = pJObjArray.getJSONObject(i); // inputs necesarry elements to the ListPosts function postsHelper.setPost(pJObj_data.getInt("id"), pJObj_data.getString("post_title"), pJObj_data.getString("post_content")); } } catch (JSONException e) { //Toast.makeText(JSonActivity.this, e.toString(), Toast.LENGTH_LONG).show(); Log.d("Json","Exception = "+e.toString()); } postsHelper.ListPosts(); } } } 时遇到问题。我做到了:

sin

但是,当我在计算器中键入include Math puts sin(5) # => -0.9589242746631385 时,它将输出sin(5)。同样,我尝试使用方程pi = x * sin(180 / x)计算PI的值,尽管我在计算器上得到了PI的值,但还是遇到了问题。

0.087155742

谢谢任何人的帮助。

1 个答案:

答案 0 :(得分:2)

您的方程式用于计算角度的正弦度数。

大多数(也许是所有)计算机语言sin()函数期望角度为弧度。

不幸的是,您需要为pi设置一个值,以便将其从一个转换为另一个。因此,除非找到渐进式实施,否则您将陷入困境。

这是因为您的公式来自弧度和度之间的2×π/ 360或π/ 180转换。