计算机小混子 2022-09-14 22:38 采纳率: 100%
浏览 19
已结题

泰勒公式求sin(x)感觉没问题啊,但是为什么得不出正确结果

img


截屏2022-09-14 22.37.23 (2).png


#include <iostream>
#include <cmath>
using namespace std;
double m_sin(double x)
{
    double T,sum = 0;
    double t = x;
    int n = 1;
    long v = 1e-6;
    do
    {
        sum = sum + t;//累加
        n++;//迭代
        t = -t * x * x/(2 * n-1)/(2 * n - 2);//每次乘x^2,变号

    }while (fabs(t)>=v);//循环结束条件
    return sum;//返回m_sin(x)的值
}
int main()
{
    double seita;
    cout<<"请输入角度值(0-360):"<<endl;
    cin>>seita;
    cout<<"sin("<<seita<<")"<<"的值是:"<<m_sin(seita)<<endl;
    return 0;
}
  • 写回答

1条回答 默认 最新

  • 快乐鹦鹉 2022-09-14 22:52
    关注
    double fz = x;
    long long fm = 1;
    double item = fz/fm;
    double sinx= 0;
    int flag = 1;
    int n = 1;
    do
    {
         sinx += item*flag;
         fz *= x*x;
         fm *= (n+1)*(n+2);
         item = fz/fm;
         flag = -flag;
         n+=2;
    }while(item >= 1e-6);
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 9月27日
  • 已采纳回答 9月19日
  • 创建了问题 9月14日

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起