Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add an algorithm to find Taylor series approximation of exponential f…#1160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
raklaptudirm merged 7 commits intoTheAlgorithms:masterfromprashalruchiranga:prashal-5
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletionsMaths/ExponentialFunction.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
/**
* @function exponentialFunction
* @description Calculates the n+1 th order Taylor series approximation of exponential function e^x given n
* @param {Integer} power
* @param {Integer} order - 1
* @returns exponentialFunction(2,20) = 7.3890560989301735
* @url https://en.wikipedia.org/wiki/Exponential_function
*/
function exponentialFunction (power, n) {
let output = 0
let fac = 1
if (isNaN(power) || isNaN(n) || n < 0) {
throw new TypeError('Invalid Input')
}
if (n === 0) { return 1 }
for (let i = 0; i < n; i++) {
output += (power ** i) / fac
fac *= (i + 1)
}
return output
}

export {
exponentialFunction
}
16 changes: 16 additions & 0 deletionsMaths/test/ExponentialFunction.test.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
import { exponentialFunction } from '../ExponentialFunction'

describe('Tests for exponential function', () => {
it('should be a function', () => {
expect(typeof exponentialFunction).toEqual('function')
})

it('should throw error for invalid input', () => {
expect(() => exponentialFunction(2, -34)).toThrow()
})

it('should return the exponential function of power of 5 and order of 21', () => {
const ex = exponentialFunction(5, 20)
expect(ex).toBe(148.4131078683383)
})
})

[8]ページ先頭

©2009-2025 Movatter.jp