-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Example for Lorenz attractor (#3018)
* broadcasting * Simplified broadcasting * Updated for broadcasting * Changed to camel case * Camel case and auto formating * Added comments * Skip if matrices have the same size * Fixed issue with undefined variable missing dot in `A._size` * Implemented broadcasting in all functions * Added helper functions * Added function to check for broadcasting rules * Tests for broadcasted arithmetic * Fixed issue with matrix the size of a vector * Documented and updated broadcasting * Included broadcast.test * Included math to syntax when missing * Lorenz attractor --------- Co-authored-by: David Contreras <[email protected]> Co-authored-by: Jos de Jong <[email protected]>
- Loading branch information
1 parent
49a19ca
commit 856b948
Showing
2 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -217,9 +217,9 @@ Evan Miller <[email protected]> | |
Timur <[email protected]> | ||
Ari Markowitz <[email protected]> | ||
Jay Wang <[email protected]> | ||
David Contreras <[email protected]> | ||
Jaeu Jeong <[email protected]> | ||
cyavictor88 <[email protected]> | ||
David Contreras <[email protected]> | ||
Jakub Riegel <[email protected]> | ||
Angus Comrie <[email protected]> | ||
TMTron <[email protected]> | ||
|
This file contains 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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<title>math.js | Lorenz Attractor</title> | ||
<script src="../../lib/browser/math.js"></script> | ||
|
||
<script src="https://cdn.plot.ly/plotly-2.25.2.min.js" charset="utf-8"></script> | ||
</head> | ||
|
||
<body> | ||
<div id="LorenzGraph"></div> | ||
</body> | ||
<script defer> | ||
|
||
// define the constants for the Lorenz attractor | ||
const sigma = 10 | ||
const beta = 2.7 | ||
const rho = 28 | ||
|
||
// solve the Lorenz attractor | ||
const sol = math.solveODE(lorenz, [0, 100], [1, 1, 1]) | ||
|
||
// make colors that represents time differences in the solution | ||
const diff = math.diff(sol.t) | ||
const color = [diff[0], ...diff] | ||
|
||
// render the plot using plotly | ||
Plotly.newPlot('LorenzGraph', | ||
[{ | ||
x: sol.y.map(u => u[0]), | ||
y: sol.y.map(u => u[1]), | ||
z: sol.y.map(u => u[2]), | ||
line: { color, colorscale: 'Jet' }, | ||
type: "scatter3d", | ||
mode: "lines" | ||
}], | ||
{ width: 800, height: 600 } | ||
) | ||
|
||
// define the lorenz attractor | ||
function lorenz(t, u) { | ||
const [x, y, z] = u | ||
return [ | ||
sigma * (y - x), | ||
x * (rho - z) - y, | ||
x * y - beta * z | ||
] | ||
} | ||
</script> | ||
|
||
</html> |