- 1
how can i write taylor series in c++?
i'm beginner so please write with common algorithms .
4 Antworten
+ 5
https://code.sololearn.com/c7zK3724Ny3e/?ref=app
https://code.sololearn.com/cKFIT3Mhli62/?ref=app
https://code.sololearn.com/c1uu2LDlqjGt/?ref=app
https://code.sololearn.com/c6BN0610sk25/?ref=app
https://code.sololearn.com/c6SyD3CCrQKm/?ref=app
https://code.sololearn.com/cEQuQKVO816n/?ref=app
https://code.sololearn.com/c9x2786FZf7d/?ref=app
https://code.sololearn.com/cZK7hgRQDhcZ/?ref=app
https://code.sololearn.com/cKWOGIIBLxO0/?ref=app
https://code.sololearn.com/cErUH9lovm2Q/?ref=app
https://code.sololearn.com/cL7h06stH204/?ref=app
https://code.sololearn.com/c28ESrHkaQw3/?ref=app
https://code.sololearn.com/clNVe3NU2J6T/?ref=app
https://code.sololearn.com/cGfDQePIBEXY/?ref=app
+ 2
Do you just want the formula displayed?
+ 1
if you want to approximate a function try this
for example exp(x) = 1 + x/1! + x^2/2! + x^3/3! ...
#include <iostream>
#include <math.h>
#include <iomanip>
#define _MAX 20
/*
if you use a numbr > 20 the variable will overflow because of factorial!
*/
uint64_t fact(uint64_t x)
{
if (x == 1)
return 1;
return x * fact(x - 1);
}
int main(int argc, char *argv[])
{
long double e = 1, x = 1.6;
for (uint64_t k = 1; k < _MAX; k++)
e += pow(x, k) / fact(k);
std::cout << std::setprecision(_MAX) << "exp(x) = " << e;
}