taylor-series

Python: Approximating ln(x) using Taylor Series

我的未来我决定 提交于 2019-12-11 03:35:13
问题 I'm trying to build an approximation for ln(1.9) within ten digits of accuracy (so .641853861). I'm using a simple function I've built from ln[(1 + x)/(1 - x)] Here is my code so far: # function for ln[(1 + x)/(1 - x)] def taylor_two(r, n): x = 0.9 / 2.9 i = 1 taySum = 0 while i <= n: taySum += (pow(x,i))/(i) i += 2 return 2 * taySum print taylor_two(x, 12) print taylor_two(x, 17) What I need to do now is reformat this so that it tells me the number of terms needed to approximate ln(1.9) to

Taylor series of function e^x

假装没事ソ 提交于 2019-12-08 14:21:04
问题 Given a number x. You need to calculate sum of Taylor Series of e^x. e^x = 1 + x + x^2/2! + x^3/3! + ... Calculate sum until a general number is lower or equal to 10^(-9). Down below is my solution but it is wrong for x<0 numbers. Do you have any idea how to fix this to work for negative numbers. int x,i,n; long long fact; //fact needs to be double double sum=0,k=1; scanf("%d",&x); i=0; sum=0; k=1; while (fabs(k)>=1.0E-9) { fact=1; for (int j=1;j<=i;++j) fact*=j; k=pow(x,i)/fact; sum+=k; ++i;

Taylor Series in MIPS assembly

夙愿已清 提交于 2019-12-08 01:20:38
问题 I'm trying to calculate the Taylor Series 1 + x + x 2 / 2! + x 3 / 3! + ... + x 10 / 10!. My program gives me infinity every time, I'm brand new to MIPS. I am only concerned about the input when it is between 0 and 10, inclusive. we are stopping at x n / n! when n = 10. Heres what I came up with: # A program to first, find the power of x^n and the factorial of n. x,n are both between 0-10 inclusive. Then it finds the taylor series .data pr1: .asciiz "Enter Float x: " .text .globl main main:

Assign Taylor expansion to function

偶尔善良 提交于 2019-12-07 05:18:25
问题 When I use Maxima to calculate the Taylor series: f(x,y) := taylor((x+y)^3, [x, y], [2, 3], 2); f(2,3); /* error: wrong number of arguments */ Basically I want to define a function as a expansion of (x+y)^3 , which takes in x,y as parameter. How can I achieve this? 回答1: Try (%i1) f(x,y) := ''(ratdisrep(taylor(('x+'y)^3, ['x, 'y], [2, 3], 2))) $ (%i2) f(2, 3); (%o2) 125 or (%i1) define(f(x, y), ratdisrep(taylor(('x+'y)^3, ['x, 'y], [2, 3], 2)))$ (%i2) f(2, 3); (%o2) 125 来源: https:/

Taylor series expansion as constexpr

こ雲淡風輕ζ 提交于 2019-12-05 15:49:55
I'm trying to build a simple sine function using taylor series expansion that can be evaluated at compile time using C++14 constexpr . My code is compiling, but the compiler doesn't generate a constant. sine is defined as follows: template <int P, typename T = double> constexpr T sine(T x) { T result = x; for (int i = 1; i < P; ++i) result += power<T>(-1, i) * power<T>(x, 1 + 2 * i) / factorial<T>(1 + 2 * i); return result; } I can provide code for power and factorial if needed. They are trivial and also constexpr . I'm calling sine from within a loop like this: template <int N> void test

Assign Taylor expansion to function

夙愿已清 提交于 2019-12-05 11:27:53
When I use Maxima to calculate the Taylor series: f(x,y) := taylor((x+y)^3, [x, y], [2, 3], 2); f(2,3); /* error: wrong number of arguments */ Basically I want to define a function as a expansion of (x+y)^3 , which takes in x,y as parameter. How can I achieve this? Try (%i1) f(x,y) := ''(ratdisrep(taylor(('x+'y)^3, ['x, 'y], [2, 3], 2))) $ (%i2) f(2, 3); (%o2) 125 or (%i1) define(f(x, y), ratdisrep(taylor(('x+'y)^3, ['x, 'y], [2, 3], 2)))$ (%i2) f(2, 3); (%o2) 125 来源: https://stackoverflow.com/questions/23294656/assign-taylor-expansion-to-function

Picking good first estimates for Goldschmidt division

跟風遠走 提交于 2019-12-04 10:09:05
问题 I'm calculating fixedpoint reciprocals in Q22.10 with Goldschmidt division for use in my software rasterizer on ARM. This is done by just setting the numerator to 1, i.e the numerator becomes the scalar on the first iteration. To be honest, I'm kind of following the wikipedia algorithm blindly here. The article says that if the denominator is scaled in the half-open range (0.5, 1.0], a good first estimate can be based on the denominator alone: Let F be the estimated scalar and D be the

Picking good first estimates for Goldschmidt division

为君一笑 提交于 2019-12-03 05:01:39
I'm calculating fixedpoint reciprocals in Q22.10 with Goldschmidt division for use in my software rasterizer on ARM. This is done by just setting the numerator to 1, i.e the numerator becomes the scalar on the first iteration. To be honest, I'm kind of following the wikipedia algorithm blindly here. The article says that if the denominator is scaled in the half-open range (0.5, 1.0], a good first estimate can be based on the denominator alone: Let F be the estimated scalar and D be the denominator, then F = 2 - D. But when doing this, I lose a lot of precision. Say if I want to find the

Taylor Series Expansion of cos x and sin x in C Programming without using math.h and only inside int main()

安稳与你 提交于 2019-11-29 13:08:37
I'm working on a project for our school and we are required to create a program that computes the approximation of the Taylor Expansion Series of sin x and cos x , only using <stdio.h> and without user-defined functions other than int main() , of all angles from -180 to 180 in increments of +5 . the following is my code: #include <stdio.h> #define PI 3.141592653589 #define NUMBER_OF_TERMS 10 int main() { int cosctr, sinctr; double ctr, radi; double cosaccu, costerm, sinaccu, sinterm; for (ctr = -180; ctr < 185; ctr = ctr + 5) { radi = ctr * PI/180.0; cosctr = 1; cosaccu = 1; costerm = 1;