first work on julia engine branch

This commit is contained in:
2024-05-12 19:50:45 +02:00
parent cbfdbaa4eb
commit cc79833992
46 changed files with 655 additions and 222 deletions

View File

@@ -1,18 +1,11 @@
---
format:
html:
include-in-header:
text: |
<script type="application/javascript">
window.PlotlyConfig = {MathJaxConfig: 'local'}
</script>
engine: julia
---
# Ein Beispiel zur Stabilität von Gleitkommaarithmetik
## Berechnung von $\pi$ nach Archimedes
```{julia}
```julia
#| error: false
#| echo: false
#| output: false
@@ -24,44 +17,25 @@ using Base64
## see https://github.com/JuliaPlots/PlotlyJS.jl/blob/master/src/PlotlyJS.jl
## https://discourse.julialang.org/t/encode-a-plot-to-base64/27765/3
function IJulia.display_dict(p::PlotlyJS.SyncPlot)
Dict(
# "application/vnd.plotly.v1+json" => JSON.lower(p),
# "text/plain" => sprint(show, "text/plain", p),
"text/html" => let
buf = IOBuffer()
show(buf, MIME("text/html"), p)
#close(buf)
#String(resize!(buf.data, buf.size))
String(take!(buf))
end,
"image/png" => let
buf = IOBuffer()
buf64 = Base64EncodePipe(buf)
show(buf64, MIME("image/png"), p)
close(buf64)
#String(resize!(buf.data, buf.size))
String(take!(buf))
end,
)
end
function Base.show(io::IO, mimetype::MIME"text/html", p::PlotlyJS.SyncPlot)
uuid = string(UUIDs.uuid4())
show(io,mimetype,@htl("""
<div style="height: auto" id=\"$(uuid)\"></div>
<script>
require(['../js/plotly-latest.min.js'], function(plotly) {
function Base.show(io::IO, mimetype::MIME"text/html", p::PlotlyJS.SyncPlot)
uuid = string(UUIDs.uuid4())
show(io,mimetype,@htl("""
<div style="height: auto" id=\"$(uuid)\"></div>
<script>
require(['../js/plotly-latest.min.js'], function(plotly) {
plotly.newPlot($(uuid),
$(HypertextLiteral.JavaScript(json(p.plot.data))),
$(HypertextLiteral.JavaScript(json(p.plot.layout))),{responsive: true});
});
</script>
"""))
"""))
end
```
## Berechnung von $\pi$ nach Archimedes
Eine untere Schranke für $2\pi$, den Umfang des Einheitskreises, erhält man durch die
Summe der Seitenlängen eines dem Einheitskreis eingeschriebenen regelmäßigen $n$-Ecks.
Die Abbildung links zeigt, wie man beginnend mit einem Viereck der Seitenlänge $s_4=\sqrt{2}$ die Eckenzahl iterativ verdoppelt.
@@ -165,8 +139,7 @@ layout = Layout(xaxis_title="Iterationsschritte", yaxis_title="rel. Fehler",
plot([scatter(x=is, y=ϵ_A, mode="markers+lines", name="Iteration A", yscale=:log10),
scatter(x=is, y=ϵ_B, mode="markers+lines", name="Iteration B", yscale=:log10)],
layout)
```
```