zoukankan      html  css  js  c++  java
  • 对方向你转账60元--三角函数方法精确位的实现

    ,"C"

    #include <math.h>--->...

     

      emmm,60,,,,,C!

    ,sin(x),,

    sin(x),cos(x)!tan(x),cot(x),sec(x)....

    ??"acrsin(x),arccos(x),arctan(x)?".  

    ,!!!

    !

      上arcsin(x),,!!!

      接! sin(x)考!->,..

     

      1 #define PI (float)3.1415926
      2 
      3 #define _2PI  (float)6.28318
      4 
      5 #define PI_DIV_2  (float)1.570796
      6 
      7 #include <math.h>
      8 
      9 #include <stdio.h>
     10 
     11 long factorial_iteration(int n){//定义阶乘函数 
     12 
     13     int result = 1;
     14 
     15     while(n>1){
     16 
     17         result *= n;
     18 
     19         n--;
     20 
     21     }
     22 
     23     return result;
     24 
     25 }
     26 
     27 float accuracy(float a,float x){//确定你的第一问精度问题 a表示精度x表示度数 
     28 
     29     x=(x*PI)/180;//将角度转化弧度 
     30 
     31     float singsum;
     32 
     33     for(int i=1;;i++){
     34 
     35         singsum=(pow(x,2*i-1)/factorial_iteration(2*i-1));
     36 
     37         if(singsum<0.00001){
     38 
     39             return i;//返回确定精度的第几项
     40 
     41             break;
     42 
     43         }
     44 
     45     }
     46 
     47 }
     48 
     49 float _sin(float x,double n)
     50 
     51 {
     52 
     53     int sign=1;            //符号
     54 
     55     int itemCnt=n;        //泰勒技级数展开多项式的项数
     56 
     57     int k=0;        
     58 
     59     float result=0;
     60 
     61     float tx;        //展开式中各项的x^(2k)
     62 
     63     int factorial=1;    //展开式中各项的(2k+1)!
     64 
     65     x=(x*PI)/180;//将角度转化弧度 
     66 
     67     //标准化为正值  sin(-x)=-sin(x)
     68 
     69     if(x<0)
     70 
     71     {
     72 
     73         x=-x;
     74 
     75         sign *=-1; 
     76 
     77     }
     78 
     79     //标准化x值到0~2π
     80 
     81     if(x>_2PI)
     82 
     83         x-=_2PI;
     84 
     85     //把0~2π标准到0~π
     86 
     87     if(x>PI)
     88 
     89     {
     90 
     91         x-=PI;    //sin(π+x)=-sin(x)
     92 
     93         sign*=(-1);
     94 
     95     }
     96 
     97     //把0~π标准到0~π/2  sin(π-x)=sin(x) 
     98 
     99     if(x>PI_DIV_2)
    100 
    101     {
    102 
    103         x=PI-x;
    104 
    105     }
    106 
    107 
    108 
    109 
    110 
    111     tx=x;    
    112 
    113     for(k=0;k<itemCnt;k++)
    114 
    115     {
    116 
    117         if(k%2==0)
    118 
    119         {
    120 
    121             result += (tx / factorial) ; 
    122 
    123         }
    124 
    125         else
    126 
    127         {
    128 
    129             result -= (tx / factorial) ;
    130 
    131         }
    132 
    133 
    134 
    135         tx *= (x*x);
    136 
    137         factorial *= (2*(k+1));
    138 
    139         factorial *= (2*(k+1)+1);
    140 
    141     }
    142 
    143     if(sign == 1)
    144 
    145         return result;
    146 
    147     else 
    148 
    149         return -result;
    150 
    151 }
    152 
    153 int main(){
    154 
    155     double a[6]={0.8,10,25,45,175,399};
    156 
    157     for(int i=0;i<6;i++){
    158 
    159         printf("自己定义的%d的正弦函数的值为:  ",a[i]);
    160 
    161         double q=accuracy(0.0001,a[i]);
    162 
    163         int b=a[i];
    164 
    165         double result=_sin(b,q);
    166 
    167         printf("%f
    ",result);
    168 
    169         printf("程序里面自己定义的%d正弦函数值是:%f
    ",a[i],sin(a[i]*PI/180));
    170 
    171     }    
    172 
    173 } 

     

    扫一扫,按照提示获取更火好玩黑科技:

     

  • 相关阅读:
    winform解析json API数据
    c#(winform)获取本地打印机
    winform程序post提交数据API
    C#关于panle重叠
    net面试总结的题目
    委托
    最实用JS 留着学习
    dev 控件获得所有的EFDEVGRID
    c#利用WebClient和WebRequest获取网页源代码的比较
    浅谈.Net WebService开发
  • 原文地址:https://www.cnblogs.com/chenqiwei/p/RunWsh_sinx.html
Copyright © 2011-2022 走看看