Skip to content

Commit

Permalink
chore: publish [email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Mar 13, 2024
1 parent 03095ec commit 9e86a6c
Show file tree
Hide file tree
Showing 32 changed files with 629 additions and 86 deletions.
8 changes: 4 additions & 4 deletions download.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Math.js can be downloaded or linked from various content delivery networks:
<tbody>
<tr>
<td>unpkg</td>
<td><a href="https://unpkg.com/[email protected].0/">https://unpkg.com/[email protected].0/</a></td>
<td><a href="https://unpkg.com/[email protected].1/">https://unpkg.com/[email protected].1/</a></td>
</tr>
<tr>
<td>cdnjs</td>
Expand All @@ -48,9 +48,9 @@ Or download the full bundle directly from [unpkg](https://unpkg.com):

<p>
<a
href="https://unpkg.com/[email protected].0/lib/browser/math.js"
>math.js (version 12.4.0, <span id="size">200 kB</span>, minified and gzipped)</a>
and if needed the <a href="https://unpkg.com/[email protected].0/lib/browser/math.js.map">source map</a>
href="https://unpkg.com/[email protected].1/lib/browser/math.js"
>math.js (version 12.4.1, <span id="size">200 kB</span>, minified and gzipped)</a>
and if needed the <a href="https://unpkg.com/[email protected].1/lib/browser/math.js.map">source map</a>
</p>

Too large for you? Create your own [custom bundle](docs/custom_bundling.html).
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/angle_configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
</style>

<script src="https://unpkg.com/[email protected].0/lib/browser/math.js"></script>
<script src="https://unpkg.com/[email protected].1/lib/browser/math.js"></script>
</head>
<body>

Expand Down
2 changes: 1 addition & 1 deletion examples/browser/angle_configuration.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ File: [angle_configuration.html](angle_configuration.html) (click for a live dem
}
</style>

<script src="https://unpkg.com/[email protected].0/lib/browser/math.js"></script>
<script src="https://unpkg.com/[email protected].1/lib/browser/math.js"></script>
</head>
<body>

Expand Down
2 changes: 1 addition & 1 deletion examples/browser/basic_usage.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>math.js | basic usage</title>
<script src="https://unpkg.com/[email protected].0/lib/browser/math.js"></script>
<script src="https://unpkg.com/[email protected].1/lib/browser/math.js"></script>
</head>
<body>

Expand Down
2 changes: 1 addition & 1 deletion examples/browser/basic_usage.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ File: [basic_usage.html](basic_usage.html) (click for a live demo)
<head>
<meta charset="utf-8">
<title>math.js | basic usage</title>
<script src="https://unpkg.com/[email protected].0/lib/browser/math.js"></script>
<script src="https://unpkg.com/[email protected].1/lib/browser/math.js"></script>
</head>
<body>

Expand Down
2 changes: 1 addition & 1 deletion examples/browser/currency_conversion.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<title>math.js | currency conversion</title>

<script src="https://unpkg.com/[email protected].0/lib/browser/math.js"></script>
<script src="https://unpkg.com/[email protected].1/lib/browser/math.js"></script>

<style>
body,
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/currency_conversion.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ File: [currency_conversion.html](currency_conversion.html) (click for a live dem
<meta charset="utf-8">
<title>math.js | currency conversion</title>

<script src="https://unpkg.com/[email protected].0/lib/browser/math.js"></script>
<script src="https://unpkg.com/[email protected].1/lib/browser/math.js"></script>

<style>
body,
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/custom_separators.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
</style>

<script src="https://unpkg.com/[email protected].0/lib/browser/math.js"></script>
<script src="https://unpkg.com/[email protected].1/lib/browser/math.js"></script>
</head>
<body>

Expand Down
2 changes: 1 addition & 1 deletion examples/browser/custom_separators.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ File: [custom_separators.html](custom_separators.html) (click for a live demo)
}
</style>

<script src="https://unpkg.com/[email protected].0/lib/browser/math.js"></script>
<script src="https://unpkg.com/[email protected].1/lib/browser/math.js"></script>
</head>
<body>

Expand Down
24 changes: 22 additions & 2 deletions examples/browser/lorenz.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,25 @@
<head>
<meta charset="UTF-8">
<title>math.js | Lorenz Attractor</title>
<script src="https://unpkg.com/[email protected].0/lib/browser/math.js"></script>
<script src="https://unpkg.com/[email protected].1/lib/browser/math.js"></script>

<script src="https://cdn.plot.ly/plotly-2.25.2.min.js" charset="utf-8"></script>
<style>
html, body {
width: 100%;
height: 100vh;
padding: 0;
margin: 0;
}
body {
display: flex;
flex-direction: column;
}

#LorenzGraph {
flex: 1;
}
</style>
</head>

<body>
Expand Down Expand Up @@ -36,7 +52,11 @@
type: "scatter3d",
mode: "lines"
}],
{ width: 800, height: 600 }
{
responsive: true,
uirevision: 'true',
title:"Lorenz Attractor",
}
)

// define the lorenz attractor
Expand Down
24 changes: 22 additions & 2 deletions examples/browser/lorenz.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,25 @@ File: [lorenz.html](lorenz.html) (click for a live demo)
<head>
<meta charset="UTF-8">
<title>math.js | Lorenz Attractor</title>
<script src="https://unpkg.com/[email protected].0/lib/browser/math.js"></script>
<script src="https://unpkg.com/[email protected].1/lib/browser/math.js"></script>

<script src="https://cdn.plot.ly/plotly-2.25.2.min.js" charset="utf-8"></script>
<style>
html, body {
width: 100%;
height: 100vh;
padding: 0;
margin: 0;
}
body {
display: flex;
flex-direction: column;
}
#LorenzGraph {
flex: 1;
}
</style>
</head>

<body>
Expand Down Expand Up @@ -45,7 +61,11 @@ File: [lorenz.html](lorenz.html) (click for a live demo)
type: "scatter3d",
mode: "lines"
}],
{ width: 800, height: 600 }
{
responsive: true,
uirevision: 'true',
title:"Lorenz Attractor",
}
)
// define the lorenz attractor
Expand Down
193 changes: 193 additions & 0 deletions examples/browser/lorenz_interactive.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>math.js | Lorenz Attractor</title>
<script src="https://unpkg.com/[email protected]/lib/browser/math.js"></script>

<script src="https://cdn.plot.ly/plotly-2.28.0.min.js" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.9/katex.min.js"
integrity="sha512-LQNxIMR5rXv7o+b1l8+N1EZMfhG7iFZ9HhnbJkTp4zjNr5Wvst75AqUeFDxeRUa7l5vEDyUiAip//r+EFLLCyA=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.9/katex.min.css"
integrity="sha512-fHwaWebuwA7NSF5Qg/af4UeDx9XqUpYpOGgubo3yWu+b2IQR4UeQwbb42Ti7gVAjNtVoI/I9TEoYeu9omwcC6g=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
<style>
body,
html {
width: 100%;
height: 100vh;
padding: 0;
margin: 0;
}

body {
display: flex;
flex-direction: column;
}

#LorenzGraph {
flex: 1;
}

#inputsDiv {
z-index: 1;
position: absolute;
background: white;
}
</style>
</head>

<body>
<div id="LorenzGraph"></div>
<div id="inputsDiv">
<fieldset name="inputs" id="inputs">
<legend for="inputs">Inputs:</legend>
<table>
<tr>
<td>
<label for="sigma" id="sigmaLabel">sigma</label>
</td>
<td>
<input type="range" id="sigma" name="sigma" value=10 min=9 max=11 step=0.01>
</td>
<td>
<label for="beta" id="betaLabel">beta</label>
</td>
<td>
<input type="range" id="beta" name="beta" value=8/3 min=2 max=4 step=0.01>
</td>
<td>
<label for="rho" id="rhoLabel">rho</label>
</td>
<td>
<input type="range" id="rho" name="rho" value=28 min=20 max=30 step=0.01>
</td>
</tr>
<tr>
<td>
<label for="x0" id="x0Label">x0</label>
</td>
<td>
<input type="range" id="x0" name="x0" value=1 min=-5 max=5 step=0.01>
</td>
<td>
<label for="y0" id="y0Label">y0</label>
</td>
<td>
<input type="range" id="y0" name="y0" value=1 min=-5 max=5 step=0.01>

</td>
<td>
<label for="z0" id="z0Label">z0</label>
</td>
<td>
<input type="range" id="z0" name="z0" value=0 min=-5 max=5 step=0.01>
</td>
</tr>
<tr>
<td>
<label for="epsilon" id="epsilonLabel">epsilon</label>
</td>
<td>
<input type="range" id="epsilon" name="epsilon" value=0.01 min=0.0001 max=0.1 step=0.0001>
</td>
</tr>
</table>
</fieldset>
</div>
</body>
<script defer>
katex.render(String.raw`\sigma`, document.querySelector("#sigmaLabel"))
katex.render(String.raw`\beta`, document.querySelector("#betaLabel"))
katex.render(String.raw`\rho`, document.querySelector("#rhoLabel"))
katex.render(String.raw`x_0`, document.querySelector("#x0Label"))
katex.render(String.raw`y_0`, document.querySelector("#y0Label"))
katex.render(String.raw`z_0`, document.querySelector("#z0Label"))
katex.render(String.raw`\epsilon`, document.querySelector("#epsilonLabel"))

const inputs = document.querySelector("#inputs")

// define the constants for the Lorenz attractor
const sigma = document.querySelector("#sigma")
const beta = document.querySelector("#beta")
const rho = document.querySelector("#rho")

// define the initial location
const x0 = document.querySelector('#x0')
const y0 = document.querySelector('#y0')
const z0 = document.querySelector('#z0')

// define the tolerance for the solution
const epsilon = document.querySelector('#epsilon')

const layout = {
interactive: true,
title: 'Lorenz Attractor',
uirevision: 'true',
sliders: [{
name: 'sigma',
currentvalue: {
xanchor: 'right',
prefix: 'color: ',
font: {
color: '#888',
size: 20
}
},
steps: [{ label: 'g', method: "updateSolution" }, { label: 'f' }]
}]
}

const t_span = [0, 100]

inputs.addEventListener("change", updateSolution)

let trace
// solve the Lorenz attractor with the initial values
updateSolution()

// crates a trace in the format needed for plotly
function createTrace(sol) {
// make colors that represents time differences in the solution
const diff = math.diff(sol.t)
const color = [diff[0], ...diff]
const trace = [{
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"
}]
return trace
}

function createLorenz(sigma, rho, beta) {
// define the lorenz attractor as a function of t and u in the format needed for solveODE
return function lorenz(t, u) {
const [x, y, z] = u
// return x', y', z'
return [
sigma * (y - x),
x * (rho - z) - y,
x * y - beta * z
]
}
}

function updateSolution() {
const y_0 = [x0.value, y0.value, z0.value]
const sol = math.solveODE(createLorenz(sigma.value, rho.value, beta.value), t_span, y_0, { tol: epsilon.value })
trace = createTrace(sol)
// reactively render the plot on update
Plotly.react('LorenzGraph', trace, layout)
}

</script>

</html>
Loading

0 comments on commit 9e86a6c

Please sign in to comment.