-
-
Notifications
You must be signed in to change notification settings - Fork 359
Forward Euler in JavaScript #418
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Butt4cak3
merged 20 commits into
algorithm-archivists:master
from
depate:euler_javascript
Oct 27, 2018
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
0619e57
Delete monte_carlo_pi.f90
depate ecf82ab
Merge branch 'master' of https://github.com/algorithm-archivists/algo…
depate 3e86449
init
depate b9e0828
Merge branch 'master' of https://github.com/algorithm-archivists/algo…
depate 5d1602a
further implementation
depate 1ea8e18
next
depate b9f0caa
Merge branch 'master' of https://github.com/algorithm-archivists/algo…
depate 76f5ca2
Merge branch 'master' of https://github.com/algorithm-archivists/algo…
depate 99b3b36
Merge branch 'master' of github.com:depate/algorithm-archive
depate 46f7300
Merge branch 'bubblesort_fortran' of github.com:depate/algorithm-archive
depate 2917f32
Added bubble.f90
depate 2bb14be
Merge branch 'master' of https://github.com/algorithm-archivists/algo…
depate 824060b
hopefully fixes things
depate 7d8917e
Merge branch 'master' of https://github.com/algorithm-archivists/algo…
depate 64a2fc8
Merge branch 'master' of github.com:depate/algorithm-archive
depate 252f9c3
implementation & documentaiion
depate fd1842c
Fixed the raised issues from the review
depate 14aa6fa
Using a arrow function
depate ce1dc90
Update euler.js
depate 71d7fa2
Merge branch 'master' into euler_javascript
Butt4cak3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
function forwardEuler(time_step, n) { | ||
function forwardEuler(timeStep, n) { | ||
const arr = [1]; | ||
for (let i = 1; i <= n; i++) { | ||
arr[i] = arr[i - 1] - 3 * arr[i - 1] * time_step; | ||
arr[i] = arr[i - 1] - 3 * arr[i - 1] * timeStep; | ||
} | ||
return arr; | ||
} | ||
|
||
function checkEuler(arr, time_step, threshold) { | ||
const is_approx = true; | ||
arr.forEach(function callback(value, i) { | ||
const solution = Math.exp(-3 * time_step * i); | ||
function checkEuler(arr, timeStep, threshold) { | ||
const isApprox = true; | ||
arr.forEach((_value, i) => { | ||
const solution = Math.exp(-3 * timeStep * i); | ||
|
||
if (Math.abs(arr[i] - solution) > threshold) { | ||
console.log(arr[i], solution); | ||
is_approx = false; | ||
isApprox = false; | ||
} | ||
}); | ||
return is_approx; | ||
return isApprox; | ||
} | ||
|
||
function main() { | ||
const time_step = 0.01; | ||
const timeStep = 0.01; | ||
const threshold = 0.01; | ||
const n = 100; | ||
var euler_result = forwardEuler(time_step, n); | ||
var check_result = checkEuler(euler_result, time_step, threshold); | ||
console.log(check_result); | ||
let eulerResult = forwardEuler(timeStep, n); | ||
let checkResult = checkEuler(eulerResult, timeStep, threshold); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. GH did not notice me about the new review. I'm on it tomorrow. |
||
console.log(checkResult); | ||
} | ||
|
||
main(); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You made this a
const
, but you try to assign a new value further down. This function will either returntrue
or crash. This is one of those cases wherelet
is required.