taylor series in c++

hello

please see this picture http://img104.herosh.com/2010/07/09/457215330.jpg

now my question if x = 2.3145

Q1 how much will be cosine, sine and tangent?

Q2 i tried to ues the above fourmlaes to find the value of x but it's not correct,so could you please show me how can i cuclate it?

please note that i'm really poor in math

then after i know the answers i can do it in c++

waiting for you
If you don't know the answer to Q1, how can you tell the sum is not correct?
You can get the values for Q1 with any calculator (make sure to work in RAD mode). Or with the cos, sin, tan functions in C++ for that matter.

I checked and both series are correct.
hello Athar (326)

because i have examples in my question note!

how you got the answers? i tried using the fourmla but it's not the same
now it's correct if i type sin(2.3.145) in cuclater so will equals to 0.735966

but what is the fourmlas for?? the fourmlas make me confuse
Last edited on
Why? Surely you learned about division, powers and factorials in school?
x³ is short for x*x*x
3! is short for 1*2*3


I used the following code to verify:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <cmath>
using namespace std;

double fac(int n)
{
  double f=n;
  while (--n)f*=n;
  return f;
}

int main(int argc, char *argv[])
{
  const double x=2.3145;
  double cos_approx=1;
  for (int i=0;i<20;i++)cos_approx+=(i%2? 1 : -1)*pow(x,i*2+2)/fac(i*2+2);
  cout << "cos(x): " << cos(x) << endl << "cos approx.: " << cos_approx << endl;

  double sin_approx=x;
  for (int i=0;i<20;i++)sin_approx+=(i%2? 1 : -1)*pow(x,i*2+3)/fac(i*2+3);
  cout << "sin(x): " << sin(x) << endl << "sin approx.: " << sin_approx << endl;
}
i know x³ is short for x*x*x
3! is short for 1*2*3

but now i don't understand the forumla above for what if i can type sin(x) in any cuclater



Topic archived. No new replies allowed.