Skip to content
Permalink
Browse files

Added complex exp and fixed complex factorial

  • Loading branch information...
kepempem committed Jul 18, 2019
1 parent c090c15 commit e3f7386951f56f5fbf55c2b92cdca3713f0aaa52
Showing with 30 additions and 19 deletions.
  1. +2 −1 code/Constants.js
  2. +8 −7 code/Functions.js
  3. +3 −1 docs/Constants.md
  4. +10 −0 docs/Functions.md
  5. +3 −3 docs/Integration.md
  6. +1 −1 package.json
  7. +3 −6 test.js

Some generated files are not rendered by default. Learn more.

@@ -7,7 +7,7 @@ const FupperBound = Math.pow(10, 6);
const eps = Math.pow(10, -10);
const realUnit = new Complex(1, 0);
const imaginaryUnit = new Complex(0, 1);

const complexE = new Complex(Math.E);

// Real Functions (R -> R)

@@ -164,23 +164,20 @@ const Factorial = (z)=>{

const ComplexFactorial = z=>{
let s = new Complex(0);
for(let j=1;j<=upperBound;j++){
for(let j=1;j<=FupperBound;j++){
let _j = toComplex(j);
s.setC(
s.add(
_j
.pow(z)
.divide(
toComplex(Math.E)
.pow(
toComplex(j/k)
)
exp(j/Fk)
)
)
);
}
return s.divide(
toComplex(k)
toComplex(Fk)
.pow(z.add(1))
);
};
@@ -277,6 +274,9 @@ const cis = x=>{
};


const exp = x=>complexE.pow(x);


const ln = x=>{
if(typeof x == "number"){
return new Complex(Math.log(x));
@@ -335,6 +335,7 @@ module.exports={
cos,
tan,
cis,
exp,
ln,
log,
abs
@@ -13,11 +13,13 @@
+ The Euler Mascheroni Constant
+ The Omega Constant
+ li(2)
+ The Golden Ratio

``MathPKG.Constants`` contains the following constants:

* ``MathPKG.Constants.PI`` - Pi
* ``MathPKG.Constants.E`` - e
* ``MathPKG.Constants.GAMMA`` - The Euler Mascheroni Constant
* ``MathPKG.Constants.OMEGA`` - The Omega constant, solution of the equation ``x * exp(x) = 1``.
* ``MathPKG.Constants.LI2`` - The logarithmic integral of `2`, the area under the curve of `1/(ln t)` from `t=0` to `t=2`.
* ``MathPKG.Constants.LI2`` - The logarithmic integral of `2`, the area under the curve of `1/(ln t)` from `t=0` to `t=2`.
* ``MathPKG.Constants.GOLDEN_RATIO`` - The Golden Ratio
@@ -25,6 +25,7 @@
+ [cos(x)](#cosx)
+ [tan(x)](#tanx)
+ [cis(x)](#cisx)
+ [exp(x)](#expx)
+ [ln(x)](#lnx)
+ [log(x, b)](#logx-b)
+ [abs(z)](#absz)
@@ -228,6 +229,15 @@ Valid for all complex numbers, `x` can be either real or `Complex`. The function
let c = Functions.cis(3); // = -0.9899924966004454 + 0.1411200080598672i
```

## exp(x)
The complex exponential function. The function calculates `e ^ x` and returns the result. `x` can be either real or `Complex`. The function returns an instance of `Complex`.
```
let pi_i = new Complex(0, Math.PI);
let euler = Functions.exp(pi_i)
.round(10); // = e ^ (i*pi) = -1 + 0i
```


## ln(x)
The natural logarithm. Valid for `C \ {0}` (All complex number except `0`). `x` can be either real or `Complex`. The function returns an instance of `Complex`.
```
@@ -22,7 +22,7 @@ const {RiemannSum} = MathPKG;

![Left Riemann Sum](../media/left.gif)

Calculates the left side Riemann sum of `f(x)` from `x=a` to `x=b`. In the geometric sense, `n` is the number of "rectangles", the bigger `n` is, the more accurate the calculation will be. When `n = 0`, the function sets `n` so that the length of one rectangle on the x-axis is `l`. By default, `n` is `0` and `l` is `10 ^ -3`, making the calculation extremly accurate. The left side sum is usually a little bit less than the actual area.
Calculates the left side Riemann sum of `f(x)` from `x=a` to `x=b`. In the geometric sense, `n` is the number of "rectangles", the bigger `n` is, the more accurate the calculation will be. If `n = 0`, the function sets `n` so that the length of one rectangle on the x-axis is `l`. By default, `n` is `0` and `l` is `10 ^ -3`, making the calculation extremly accurate. The left side sum is usually a little bit less than the actual area.
```
let area = RiemannSum.left(0,10,x=>x); // = 49.995000000000005
```
@@ -31,13 +31,13 @@ let area = RiemannSum.left(0,10,x=>x); // = 49.995000000000005

![Right Riemann Sum](../media/right.gif)

Calculates the right side Riemann sum of `f(x)` from `x=a` to `x=b`. In the geometric sense, `n` is the number of "rectangles", the bigger `n` is, the more accurate the calculation will be. When `n = 0`, the function sets `n` so that the length of one rectangle on the x-axis is `l`. By default, `n` is `0` and `l` is `10 ^ -3`, making the calculation extremly accurate. The right side sum is usually a little bit more than the actual area.
Calculates the right side Riemann sum of `f(x)` from `x=a` to `x=b`. In the geometric sense, `n` is the number of "rectangles", the bigger `n` is, the more accurate the calculation will be. If `n = 0`, the function sets `n` so that the length of one rectangle on the x-axis is `l`. By default, `n` is `0` and `l` is `10 ^ -3`, making the calculation extremly accurate. The right side sum is usually a little bit more than the actual area.
```
let area = RiemannSum.right(0,10,x=>x); // = 50.005
```

## avg(a, b, f[, n = 0, l = 10 ^ -3])
Calculates the average of the left side and right side Riemann sums of `f(x)` from `x=a` to `x=b`. In the geometric sense, `n` is the number of "rectangles", the bigger `n` is, the more accurate the calculation will be. When `n = 0`, the function sets the `n` so that the length of one rectangle on the x-axis is `l`. By default, `n = 0` and `l = 10 ^ -3`, making the calculation extremly accurate. This is the most accurate method.
Calculates the average of the left side and right side Riemann sums of `f(x)` from `x=a` to `x=b`. In the geometric sense, `n` is the number of "rectangles", the bigger `n` is, the more accurate the calculation will be. If `n = 0`, the function sets the `n` so that the length of one rectangle on the x-axis is `l`. By default, `n = 0` and `l = 10 ^ -3`, making the calculation extremly accurate. This is the most accurate method.
```
let area = RiemannSum.avg(0,10,x=>x); // = 50
```
@@ -1,6 +1,6 @@
{
"name": "math-pkg-cmplx",
"version": "1.0.8",
"version": "1.0.9",
"description": "Math Library with Complex Number Functionality, Integration functions and conversion functions between numerical bases.",
"main": "index.js",
"scripts": {
@@ -7,13 +7,10 @@ const {
BaseToolbox
} = MathPKG;

let e = new Complex(Math.E);
let pi = new Complex(Math.PI);
let i = new Complex(0,1);
let pi_i = new Complex(0, Math.PI);

console.log(
e
.pow(pi.times(i))
Functions.exp(pi_i)
.round(10)
.toString()
); // e ^ i pi
); // e ^ i pi

0 comments on commit e3f7386

Please sign in to comment.
You can’t perform that action at this time.