Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/145.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;泰勒级数与三角表_C++_Taylor Series - Fatal编程技术网

C++ C++;泰勒级数与三角表

C++ C++;泰勒级数与三角表,c++,taylor-series,C++,Taylor Series,好的,我正在创建一个程序,在一个表中输出余弦、sin和其他三角值,角度0到360,增量为15。作为分配的一部分,我们需要使用C++中给定的正弦和COS命令,以及使用泰勒级数计算的正弦和余弦值来显示系统余弦和系统正弦。当我使用泰勒级数计算正弦和余弦值时,我的程序中出现了错误。我注释掉了一些代码,希望这会使它更容易查看。如有任何建议,将不胜感激。此外,我将张贴一个样本输出的程序,因为它的立场 Angle Sys Cos Cosine Sys Sin Sine Tangent C

好的,我正在创建一个程序,在一个表中输出余弦、sin和其他三角值,角度0到360,增量为15。作为分配的一部分,我们需要使用C++中给定的正弦和COS命令,以及使用泰勒级数计算的正弦和余弦值来显示系统余弦和系统正弦。当我使用泰勒级数计算正弦和余弦值时,我的程序中出现了错误。我注释掉了一些代码,希望这会使它更容易查看。如有任何建议,将不胜感激。此外,我将张贴一个样本输出的程序,因为它的立场

 Angle  Sys Cos   Cosine  Sys Sin    Sine  Tangent   Cotangent   Secant Cosecant

     0   1.0000   1.0000   0.0000   0.0000   0.0000      inf
    15   0.9659   0.0341   0.2588  -0.9659  -0.9659     -inf
    30   0.8660   0.1340   0.5000  -0.8660  -0.8660     -inf
    45   0.7071   0.2929   0.7071  -0.7071  -0.7071     -inf
    60   0.5000   0.5000   0.8660  -0.5000  -0.5000     -inf
    75   0.2588   0.7412   0.9659  -0.2588  -0.2588     -inf
    90   0.0000   1.0000   1.0000   0.0000   0.0000     -inf
   105  -0.2588   1.2588   0.9659   0.2588   0.2588     -inf
   120  -0.5000   1.5000   0.8660   0.5000   0.5000     -inf
   135  -0.7071   1.7071   0.7071   0.7071   0.7071     -inf
   150  -0.8660   1.8660   0.5000   0.8660   0.8660     -inf
   165  -0.9659   1.9659   0.2588   0.9659   0.9659     -inf
   180  -1.0000   2.0000   0.0000   1.0000   1.0000     -inf
   195  -0.9659   1.9659  -0.2588   0.9659   0.9659     -inf
   210  -0.8660   1.8660  -0.5000   0.8660   0.8660     -inf
   225  -0.7071   1.7071  -0.7071   0.7071   0.7071     -inf
   240  -0.5000   1.5000  -0.8660   0.5000   0.5000     -inf
   255  -0.2588   1.2588  -0.9659   0.2588   0.2588     -inf
   270  -0.0000   1.0000  -1.0000  -0.0000  -0.0000     -inf
   285   0.2588   0.7412  -0.9659  -0.2588  -0.2588     -inf
   300   0.5000   0.5000  -0.8660  -0.5000  -0.5000     -inf
   315   0.7071   0.2929  -0.7071  -0.7071  -0.7071     -inf
   330   0.8660   0.1340  -0.5000  -0.8660  -0.8660     -inf
   345   0.9659   0.0341  -0.2588  -0.9659  -0.9659     -inf
   360   1.0000  -0.0000  -0.0000  -1.0000  -1.0000   0.9501

Process returned 0 (0x0)   execution time : 0.044 s
Press any key to continue.
源代码:

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

// Function Prototypes..
//  These are the only function you need to write
//      See Sample functions below main()
double Factorial(double);   // For loop version
double Sine(double);        // Taylor Series Sine
double Cosine(double);      // Taylor Series Cosine
double Tangent(double);     // Tangent(x) = Sine(x)/Cosine(x)
double Cotangent(double);   // Cotangent(x) = Cosine(x)/Sine(x)
double Secant(double);      // Secant(x) = 1.0/Cosine(x)
double Cosecant(double);    // Cosecant(x) = 1.0/Sine(x)

void PrintTrigTable(void);  // Print Trignometric Table


// This main function is complete
int main()
{
    PrintTrigTable();

    return 0;
}

// PrintTrigTable - write this function
void PrintTrigTable()
{
cout << fixed<<setw(6)<<"Angle";
cout <<fixed << setw(9) << "Sys Cos" << setw(9) << "Cosine" << setw(9) << "Sys Sin" << setw(8) << "Sine";
cout << fixed << setw(9) << "Tangent" << setw(12) << "Cotangent" << setw(9) << "Secant" << setw(9) << "Cosecant" <<endl;
for (double x = 0.0; x <= 360.0; x += 15.0)

{

    cout << fixed << setw (6) << setprecision(0) << x;

    cout << fixed << setw (9) << setprecision(4)<< cos(x*3.1415926/180);

    cout << fixed << setw (9) << setprecision(4)<< Cosine(x);

    cout << fixed << setw (9) << setprecision(4)<< sin(x*3.1415926/180);

    cout << fixed << setw (9) << setprecision(4)<< Sine(x);

    cout << fixed << setw (9) << setprecision(4)<< Tangent(x);

    cout << fixed << setw (9) << setprecision(4)<< Cotangent(x) <<endl;

    //cout << fixed << setw (9) << setprecision(4)<< Secant(x)<<endl;

    //cout << fixed << setw (9) << setprecision(4)<< Cosecant(x) <<endl;

}
}
// Factorial - write this function
double Factorail(double angle)
{
double fact = 1;
for (double i =1; i <= angle; i++)
fact *=i;
return(fact);
}

// Sine - write this function
double Sine(double angle)
{
double PI = 3.1415926;
double mysin= 0, mysin2= 9999;
double anglerad = angle*PI/180.0;
 double  c =1., counter, fact;
while (abs(mysin2-mysin)> .0001)
{

     mysin2= mysin;
     fact = 1;
    for ( double k =1; k <= counter; k++)
    fact *=k;
    mysin= mysin + pow(-1,c)*(pow(anglerad,counter)/fact);
    c = c+1;
    counter = counter +2;

}
return(mysin);
}

double Cosine(double angle)
{
double PI = 3.1415926;
double mycos= 1, mycos2= 9999;
double anglerad = angle*PI/180.0;
double c =1, counter, fact;
while (abs(mycos2-mycos)> .0001)
{

     mycos2= mycos;
     fact = 1;
    for ( double k =1; k <= counter; k++)
    fact *=k;
    mycos= mycos + pow(-1,c)*(pow(anglerad,counter)/fact);
    c = c+1;
    counter = counter +2;

}
return(mycos);
}
// Tangent - Tangent(x) = Sine(x)/Cosine(x)
double Tangent(double angle)
{
    double inf = (Sine(angle)/Cosine(angle));
    if (inf > 100)
    {
        inf =1.0/0.0;
    }
    else if (inf < -100)
    {
        inf = -1.0/0.0;
    }
    return inf;
}

// Cotangent - write this function -
double Cotangent(double angle)
{
    double inf = (Cosine(angle)/Sine( angle));
    if (inf > 100)
    {
        inf =1.0/0.0;
    }
    else if (inf < -100)
    {
        inf = -1.0/0.0;
    }
    return inf;
}

// Secant - Secant(x) = 1.0/Cosine(x)
double Secant(double angle)
{
    double inf = (1.0/Cosine(angle));
    if (inf > 100)
    {
        inf =1.0/0.0;
    }
    else if (inf < -100)
    {
        inf = -1.0/0.0;
    }
    return inf;
}

// Cosecant - write this function
double Cosecant(double angle)
{
   double inf = (1.0/Sine(angle));
    if (inf > 100)
    {
        inf =1.0/0.0;
    }
    else if (inf < -100)
    {
        inf = -1.0/0.0;
    }
    return inf;
}
#包括
#包括
#包括
使用名称空间std;
//功能原型。。
//这些是您需要编写的唯一函数
//请参见main()下面的示例函数
双阶乘(双);//For循环版本
双正弦(双);//泰勒级数正弦
双余弦(双);//泰勒级数余弦
双切线(双);//切线(x)=正弦(x)/余弦(x)
双余切(双);//余切(x)=余弦(x)/正弦(x)
双正割(双);//正割(x)=1.0/余弦(x)
双余割(双);//余割(x)=1.0/正弦(x)
void打印触发表(void);//打印三角表
//此主要功能已完成
int main()
{
PrintTrigTable();
返回0;
}
//PrintTrigTable-编写此函数
void PrintTrigTable()
{

你的问题是什么?任何错误或任何意外结果?没有错误,但如果你查看示例输出,系统余弦和余弦应该具有相等的值。以及Sys Sine和Sine值。在正弦和余弦泰勒级数中的某个地方,我的数学中有一个错误。我刚刚修复了代码的余弦部分,mycos value应该在0而不是1。我的cos+pow(-1,c)之间的正弦值也需要更改为a-。在数学上,当你有一个工作的
sin
(或
cos
)时,仍然停留在正弦值问题上,您可以使用trig恒等式计算所有其他。换句话说,除非明确要求您这样做,否则最好不要对每个计算使用(类似但不完全相同)泰勒级数;只需使用
sin(x)=cos(x-pi)
等。作业要求我这样做,否则我会按照建议使用一个简单的快捷方式。如果我没有说清楚,很抱歉。