So I am working a a project for my intro C++ class, and I am having some trouble with a function for approximating exp(x) using a taylor series. The taylor series approximations for exp(x) is: 1+x+((x^2)/2!)+((x^3)/3!+...., and I am supposed to approximate to "n" number of terms.
Thus far, my function is this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
double fact(int c)
{
int factorial=1;
for ( int i = 1; i <= c; i++ )
{
factorial *=i;
}
return factorial;
}
double taylor(double x, int n)
{
double approx;
double sum;
double value;
for (int i=1; i<=n; i++)
{
int factorial=1;
factorial*=i;
sum=((pow(x,i))/fact(i));
value+=sum;
}
approx = 1+value;
return approx;
Now this does work if I just run it by itself, i.e. just do something like "cout << taylor(x,n)". But whenever I call this function within another function, it does not work! It is kinda hard to explain, but anyone have any ideas?
Thanks
need to add "sizes" to shopping cart
Hey guys, I am trying to figure out a way to add a "size" selector on to this bit of code. I added a way to view it in the "zoom.php" page and also to select a size from the sizes
HTAccess auto log in?
Hi all.Too busy driving celebs about lately so I hope someone here can help me out.I need a script that will allow a user to access an HTAccess directory automatically, without the need of
Grids not displaying decimals, and behaving differently on different PCs?
Hello,
mod_rewrite.c on windows ??
why it's not working on windows while it's working on other hosts??? this is the code i got from a tutorial :Code: [Select]<IfModule mod_rewrite.c>RewriteEngine OnRewriteBase
PHP & Java
Hello,can PHP code be used inside java code?Code: [Select]<SCRIPT LANGUAGE="JavaScript">OpenWindow.document.write("<?php echo NotWorking;
Security Exception on pages using AJAX
I am getting the exception: attempted to perform an operation not allowed by the security policy on my AJAX pages. If i remove the AJAX control it works.
Edit MySQL Row Using PHP and HTML Form
Hello,Here's what I'm trying to do. Build a page where a user enters a MySQL row number in. Then, a new page appears with an HTML form where the user can edit the information in that row. Like for
A WBS element with the name XXX already exists in version FREI_VERSION
Hi.
Multidimensional Array into an Html table, help!
Hello all, I am new to HTML/PHP so any help would be great.I have a multidimensional array filled with values that I am trying to output into an html table. This works (outputs value of array):Code:
Class not found error
I am getting Class 'index' not found in Eval function://write config $path = dirname(__FILE__).DS.'..'.DS.'paymentclass'; if ( $model->payment_class ) { if