This commit is contained in:
jverzani
2022-05-24 13:51:49 -04:00
parent 5c0fd1b6fe
commit 244f492f9e
240 changed files with 65211 additions and 0 deletions

3
CwJ/TODO/AD.md Normal file
View File

@@ -0,0 +1,3 @@
Good paper recommended here (https://discourse.julialang.org/t/learning-automatic-differentiation/56158/3)
https://www.jmlr.org/papers/volume18/17-468/17-468.pdf

61
CwJ/TODO/arrows.md Normal file
View File

@@ -0,0 +1,61 @@
This is really just
plot!([0,cos(θ)],[0,sin(θ)], arrow=true)
https://stackoverflow.com/questions/58219191/drawing-an-arrow-with-specified-direction-on-a-point-in-scatter-plot-in-julia
https://github.com/m3g/CKP/blob/master/disciplina/codes/velocities.jl
using Plots
using LaTeXStrings
function arch(θ₁,θ₂;radius=1.,Δθ=1.)
θ₁ = π*θ₁/180
θ₂ = π*θ₂/180
Δθ = π*Δθ/180
l = round(Int,(θ₂-θ₁)/Δθ)
x = zeros(l)
y = zeros(l)
for i in 1:l
θ = θ₁ + i*Δθ
x[i] = radius*cos(θ)
y[i] = radius*sin(θ)
end
return x, y
end
plot()
x, y = arch(0,360)
plot(x,y,seriestype=:shape,label="",alpha=0.5)
x, y = arch(0,360,radius=0.95)
plot!(x,y,seriestype=:shape,label="",fillcolor=:white)
x, y = arch(0,360,radius=0.7)
plot!(x,y,seriestype=:shape,label="",alpha=0.5,fillcolor=:red)
x, y = arch(0,360,radius=0.65)
plot!(x,y,seriestype=:shape,label="",fillcolor=:white)
plot!([0,0],[0,1.1],arrow=true,color=:black,linewidth=2,label="")
plot!([0,1.1],[0,0],arrow=true,color=:black,linewidth=2,label="")
x, y = arch(15,16,radius=0.65)
plot!([0,x[1]],[0,y[1]],arrow=true,color=:black,linewidth=1,label="")
x, y = arch(35,36,radius=0.95)
plot!([0,x[1]],[0,y[1]],arrow=true,color=:black,linewidth=1,label="")
plot!(draw_arrow=true)
plot!(showaxis=:no,ticks=nothing,xlim=[-0.1,1.1],ylim=[-0.1,1.1],)
plot!(xlabel="x",ylabel="y",size=(400,400))
annotate!(0.58,-0.07,text(L"\Delta v_1",10))
annotate!(0.88,-0.07,text(L"\Delta v_2",10))
savefig("./velocities.pdf")

30
CwJ/TODO/earth.jl Normal file
View File

@@ -0,0 +1,30 @@
# Calculate the temperature of the earth using the simplest model
# @jake
# https://discourse.julialang.org/t/seven-lines-of-julia-examples-sought/50416/121
using Unitful, Plots
p_sun = 386e24u"W" # power output of the sun
radius_a = 6378u"km" # semi-major axis of the earth
radius_b = 6357u"km" # semi-minor axis of the earth
orbit_a = 149.6e6u"km" # distance from the sun to earth
orbit_e = 0.017 # eccentricity of r = a(1-e^2)/(1+ecos(θ)) & time ≈ 365.25 * θ / 360 where θ is in degrees
a = 0.75 # absorptivity of the sun's radiation
e = 0.6 # emmissivity of the earth (very dependent on cloud cover)
σ = 5.6703e-8u"W*m^-2*K^-4" # Stefan-Boltzman constant
temp_sky = 3u"K" # sky temperature
t = (0:0.25:365.25)u"d" # day of year in 1/4 day increments
θ = 2*π/365.25u"d" .* t # approximate angle around the sun
r = orbit_a * (1-orbit_e^2) ./ (1 .+ orbit_e .* cos.(θ)) # distance from sun to earth
area_projected = π * radius_a * radius_b # area of earth facing the sun
ec = sqrt(1-radius_b^2/radius_a^2) # eccentricity of earth
area_surface = 2*π*radius_a^2*(1 + radius_b^2/(ec*radius_b^2)*atanh(ec)) # surface area of the earth
q_in = p_sun * a * area_projected ./ (4 * π .* r.^2) # total heat impacting the earth
temp_earth = (q_in ./ (e*σ*area_surface) .+ temp_sky^4).^0.25 # temperature of the earth
plot(t*u"d^-1", temp_earth*u"K^-1" .- 273.15, label = false, title = "Temperature of Earth", xlabel = "Day", ylabel = "Temperature [C]")

View File

@@ -0,0 +1,115 @@
###### Question (Ladder [questions](http://www.mathematische-basteleien.de/ladder.htm))
A ``7``meter ladder leans against wall with the base ``1.5``meters from wall at its base. At which height does the ladder touch the wall?
```julia; hold=true; echo=false
l = 7
adj = 1.5
opp = sqrt(l^2 - adj^2)
numericq(opp, 1e-3)
```
----
A ``7``meter ladder leans against the wall. Between the ladder and the wall is a ``1``m cube box. The ladder touches the wall, the box and the ground. There are two such positions, what is the height of the ladder of the more upright position?
You might find this code of help:
```julia; eval=false
@syms x y
l, b = 7, 1
eq = (b+x)^2 + (b+y)^2
eq = subs(eq, x=> b*(b/y)) # x/b = b/y
solve(eq ~ l^2, y)
```
What is the value `b+y` in the above?
```julia; echo=false
radioq(("The height of the ladder",
"The height of the box plus ladder",
"The distance from the base of the ladder to the box,"
"The distance from the base of the ladder to the base of the wall"
),1)
```
What is the height of the ladder
```julia; hold=true; echo=false
numericq(6.90162289514212, 1e-3)
```
----
A ladder of length ``c`` is to moved through a 2-dimensional hallway of width ``b`` which has a right angled bend. If ``4b=c``, when will the ladder get stuck?
Consider this picture
```julia; hold=true; echo=false
p = plot(; axis=nothing, legend=false, aspect_ratio=:equal)
x,y=1,2
b = sqrt(x*y)
plot!(p, [0,0,b+x], [b+y,0,0], linestyle=:dot)
plot!(p, [0,b+x],[b,b], color=:black, linestyle=:dash)
plot!(p, [b,b],[0,b+y], color=:black, linestyle=:dash)
plot!(p, [b+x,0], [0, b+y], color=:black)
```
Suppose ``b=5``, then with ``b+x`` and ``b+y`` being the lengths on the walls where it is stuck *and* by similar triangles ``b/x = y/b`` we can solve for ``x``. (In the case take the largest positive value. The answer would be the angle ``\theta`` with ``\tan(\theta) = (b+y)/(b+x)``.
```julia; hold=true; echo=false
b = 5
l = 4*b
@syms x y
eq = (b+x)^2 + (b+y)^2
eq =subs(eq, y=> b^2/x)
x₀ = N(maximum(filter(>(0), solve(eq ~ l^2, x))))
y₀ = b^2/x₀
θ₀ = Float64(atan((b+y₀)/(b+x₀)))
numericq(θ₀, 1e-2)
```
-----
Two ladders of length ``a`` and ``b`` criss-cross between two walls of width ``x``. They meet at a height of ``c``.
```julia; hold=true; echo=false
p = plot(; legend=false, axis=nothing, aspect_ratio=:equal)
ya,yb,x = 2,3,1
plot!(p, [0,x],[ya,0], color=:black)
plot!(p, [0,x],[0, yb], color=:black)
plot!(p, [0,0], [0,yb], color=:blue, linewidth=5)
plot!(p, [x,x], [0,yb], color=:blue, linewidth=5)
plot!(p, [0,x], [0,0], color=:blue, linewidth=5)
xc = ya/(ya+yb)
c = yb*xc
plot!(p, [xc,xc],[0,c])
p
```
Suppose ``c=1``, ``b=3``, and ``a=5``. Find ``x``.
Introduce ``x = z + y``, and ``h`` and ``k`` the heights of the ladders along the left wall and the right wall.
The ``z/c = x/k`` and ``y/c = x/h`` by similar triangles. As ``z + y`` is ``x`` we can solve to get
```math
x = z + y = \frac{xc}{k} + \frac{xc}{h}
= \frac{xc}{\sqrt{b^2 - x^2}} + \frac{xc}{\sqrt{a^2 - x^2}}
```
With ``a,b,c`` as given, this can be solved with
```julia; hold=true; echo=false
a,b,c = 5, 3, 1
f(x) = x*c/sqrt(b^2 - x^2) + x*c/sqrt(a^2 - x^2) - x
find_zero(f, (0, b))
```
The answer is ``2.69\dots``.

BIN
CwJ/TODO/ti-30-image.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB