28 Replies  11970 Views  Last Post: 25 July 2010  11:34 AM
#1
taylor series in c++
Posted 09 July 2010  04:11 AM
please see this picture
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
Replies To: taylor series in c++
#2
Re: taylor series in c++
Posted 09 July 2010  04:36 AM
but what is the fourmlas for?? the fourmlas make me confuse
#3
Re: taylor series in c++
Posted 09 July 2010  07:14 AM
2. Then check out our snippet section
In short, The Taylor Series is an approximation of the trig function(s).
#4
Re: taylor series in c++
Posted 09 July 2010  08:28 AM
for the second link it's ok but my question
Quote
but what is the fourmlas for?? the fourmlas make me confuse
#5
Re: taylor series in c++
Posted 09 July 2010  08:37 AM
If you look at the full series, you get an infinite sum (so getting a precise value isn't possible). So I would imagine that your calculator does something along the lines of evaluating the part of the taylor series until a reasonable approximation is made.
See Here: http://en.wikipedia....ies_definitions
L.N
#6
Re: taylor series in c++
Posted 09 July 2010  09:17 AM
here is my way whan i want to use the fourma for sin(x)
lt say x = 1
sin(1) = 1  1^3/3*2*1 + 1^5/5*4*3*2*1 and so on, but this way is not correct
so i;m lookeing for the correct way ( x = 1)
so can anybody show me?
one more Q
what is the relationship between the forumlas above and this forumla
#7
Re: taylor series in c++
Posted 09 July 2010  09:31 AM
This post has been edited by xtreampb: 09 July 2010  09:33 AM
#8
Re: taylor series in c++
Posted 09 July 2010  09:31 AM
muti post
This post has been edited by xtreampb: 09 July 2010  09:34 AM
#9
Re: taylor series in c++
Posted 09 July 2010  09:32 AM
L.N
This post has been edited by LivingNightmare: 09 July 2010  09:34 AM
#10
Re: taylor series in c++
Posted 09 July 2010  11:18 AM
but my way is not correct
can you please try and show me here?
waiting for you
#11
Re: taylor series in c++
Posted 09 July 2010  11:23 AM
To evaluate sin(pi) you would calculate sin(pi) = pi  (pi^3)/3! + (pi^5)/5!  (pi^7)/7! + (pi^9)/9! ... and you would keep going until you have the desired precision. However, in this case sin(pi) is simply equal to 0. Also, note that for a positive integer N, N! = N*(N1)*(N2)*...*2*1. So 5! would be equal to 5*4*3*2*1 = 120.
L.N
#12
Re: taylor series in c++
Posted 09 July 2010  11:47 AM
#include <iostream> #include <cmath> using namespace std; double factorial(double num) { double ret = 1; while(num > 0) { ret *= num; num; } return ret; } double MySine(double rad, int n) { double value = 0; for(int i = 0; i < n; i++) { value += pow(1.0, i) / factorial((2*i) + 1) * pow(rad, ((2*i) + 1)); } return value; } int main() { double p = 3.1415926; cout<<"Sine of pi is: " <<MySine(p, 12) <<endl; return 0; }
The factorial function simply evaluates N!  Then MySine approximates Sin(rad) by using it's taylor series expansion.
L.N
#13
Re: taylor series in c++
Posted 09 July 2010  02:25 PM
and i find the correct way
first i have to do this
3!=6
5!=120
7!=5040
9!=362880
then
sin(1)=11/6+1/1201/5040+1/362880
#14
Re: taylor series in c++
Posted 09 July 2010  02:43 PM
L.N
This post has been edited by LivingNightmare: 09 July 2010  02:43 PM
#15 Guest_empror9*
Re: taylor series in c++
Posted 24 July 2010  04:42 PM
this is my function to approximate sin(x)
float sin(float x) { float result = x; int limit = 15; int sign = 1; for(int i=3 ; i<limit ; i+=2,sign=sign) result += sign*result*(x*x)/(i*(i1)); return result; }
and this to approximate cos(x)
float cos(float x) { float result = 1; int limit = 15; int sign = 1; for(int i=2 ; i<limit ; i+=2,sign=sign) result += sign*result*(x*x)/(i*(i1)); return result; }
but the answer is not clear in some cases and in other cases it displays wrong answers
try to input 1.5707963
cos should equals to 0.0000000
but my function shows 0.263853, so the answer is not that good
waiting for you
