taylor-series

How to implement maclaurin series in keras?

梦想与她 提交于 2020-06-24 09:16:02
问题 I am trying to implement expandable CNN by using maclaurin series. The basic idea is the first input node can be decomposed into multiple nodes with different orders and coefficients. Decomposing single nodes to multiple ones can generate different non-linear line connection that generated by maclaurin series. Can anyone give me a possible idea of how to expand CNN with maclaurin series non-linear expansion? any thought? I cannot quite understand how to decompose the input node to multiple

EXP to Taylor series

家住魔仙堡 提交于 2020-01-13 19:21:10
问题 I'am trying to expand exp(x) function to Taylor series. Here is code: double CalcExp(){ double eps = 0.0000000000000000001; double elem = 1.0; double sum = 0.0; int i = 1; sum = 0.0; do { sum += elem; elem *= x / i; i++; } while (elem >= eps); return sum; } The problem is when I enter big X or negative X my program crashes. And when I enter X like "0.00000000001" the result is -1. Need advice. Thank's for help. 回答1: For big X values (around 700 and above), you'll hit the range limit for

Taylor Series of a Sine

隐身守侯 提交于 2020-01-07 08:29:11
问题 I'm currently in a Java class at my university and we've been asked to code a Taylor Series equation to compute a Sine function. I've coded what makes sense to me, and I've tried debugging every section of code I can think of to make sure all of the parts are functioning the way I think they should, but the program still isn't functioning right. So, I'm hoping someone might look at this and spot what I'm doing wrong. this is the equation: Taylor Series Equation public class Sine { public

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

大兔子大兔子 提交于 2019-12-24 12:43: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

Approximation of arcsin in C

寵の児 提交于 2019-12-24 12:12:08
问题 I've got a program that calculates the approximation of an arcsin value based on Taylor's series. My friend and I have come up with an algorithm which has been able to return the almost "right" values, but I don't think we've done it very crisply. Take a look: double my_asin(double x) { double a = 0; int i = 0; double sum = 0; a = x; for(i = 1; i < 23500; i++) { sum += a; a = next(a, x, i); } } double next(double a, double x, int i) { return a*((my_pow(2*i-1, 2)) / ((2*i)*(2*i+1)*my_pow(x, 2)

In what situation would a taylor series for a polynomial be necessary?

橙三吉。 提交于 2019-12-24 01:17:11
问题 I'm having a hard time understanding why it would be useful to use the Taylor series for a function in order to gain an approximation of a function, instead of just using the function itself when programming. If I can tell my computer to compute e^(.1) and it will give me an exact value, why would I take an approximation instead? 回答1: Taylor series are generally not used to approximate functions. Usually, some form of minimax polynomial is used. Taylor series converge slowly (it takes many

Taylor series expansion as constexpr

一个人想着一个人 提交于 2019-12-22 08:47:33
问题 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

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

邮差的信 提交于 2019-12-18 07:22:41
问题 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

Own asin() function (with Taylor series) not accurate

余生颓废 提交于 2019-12-12 04:25:28
问题 I need to write my own asin() function without math.h library with the use of Taylor series. It works fine for numbers between <-0.98;0.98> but when I am close to limits it stops with 1604 iterations and therefore is inaccurate. I don't know how to make it more accurete. Any suggestions are very appreciated! The code is following: #include <stdio.h> #include <stdlib.h> #include <string.h> #define EPS 0.000000000001 double my_arcsin(double x) { long double a, an, b, bn; a = an = 1.0; b = bn =

repeat loop in R to compute the cosine of 2.345 correct to 5 decimal places

与世无争的帅哥 提交于 2019-12-11 19:03:16
问题 I want to compute the cosine of 2.345 correct to 5 decimal places using Taylor series. My code is given below. I am not sure what is wrong with that. Any help is appreciated! > x<-2.345 > count<-0 > repeat{ + count<-count+1 + initial = (-1)^(n-1) + numerator = x^(2*(n-1)) + denominator = factorial(2*(n-1)) + total=(initial*numerator)/denominator + if(abs((cos(x)-total)/cos(x))*100 <= 0.00001) break + sum=sum+total + } 回答1: It's a simple matter of correcting what is wrong in your code. x <- 2