Skip to content

Commit

Permalink
bai_3_calculus_2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bacbahieu committed Mar 14, 2024
1 parent 78506e3 commit 95f1be1
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions AdvProg_L2-Calculus/calculus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,25 @@ double mySqrt(double x);
***/
double myCos(double x)
{
double ket_qua = 1 - pow(x, 2) / 2 + pow(x, 4) / 24 - pow(x, 6) / 720;
double ket_qua = 0;
int giai_thua = 1;
for (int i = 0; i < 100; i++)
{
if (i == 0)
{
giai_thua = 1;
ket_qua += pow(x, i) / giai_thua;
}
else if (i % 2 == 0)
{
giai_thua *= i;
ket_qua += pow(x, i) / giai_thua;
}
else
{
giai_thua *= i;
}
}
return ket_qua;
}

Expand All @@ -32,6 +50,27 @@ double myCos(double x)
double mySin(double x)
{
double ket_qua = x - pow(x, 3) / 6 + pow(x, 5) / 120 - pow(x, 7) / 5040;
int giai_thua = 1;
for (int i = 0; i < 100; i++)
{
if (i == 0)
{
continue;
}
else
{
giai_thua *= i;
}
if (i % 2 == 1)
{
ket_qua += pow(x, i) / giai_thua;
}
else
{
continue;
;
}
}
return ket_qua;
}

Expand All @@ -51,7 +90,7 @@ double mySqrt(double x)
else
{
double ket_qua = x;
for (int i = 0; i < 5; i++)
for (int i = 0; i < 100; i++)
{
ket_qua = (ket_qua + x / ket_qua) / 2;
}
Expand Down

0 comments on commit 95f1be1

Please sign in to comment.