= parameter(0 .. 0.05)
x fplot(sin(1 / x), yscale=0.05, npoints=11)
4 Mathematics
4.1 Mappings
4.1.1 Functions \(\mathbb{R} \to \mathbb{R}\)
= parameter(0 .. 2π)
x = sin(x)
s = cos(x)
c
= 2s
f = s + f'
g = 1 / 10 * (0.5 - x) * (pi / 2 - x) * (3pi / 2 - x) * (2pi - x)
h
= fplot(c, s, g, h)
p scatter!([0.5, pi / 2, 3pi / 2, 2pi], zeros(4), color=:tomato)
p
= parameter(-1 .. 1)
x = exp(x)
f = exp(-x)
g = exp(x - 1)
h
fplot(f, g, h, -f, -g, -h)
= parameter(-1 .. 1)
x = x
f = antiderivative(f)
F fplot(f, F)
integrate(f, 0 .. 1)
0.5
= [0, 1, 2]
p = fplot(fromroots(p, -0.1 .. 2.1))
f scatter!(p, 0 * p, color=:tomato)
f
Lagrange polynomials
= [0, 1.5, 2]
p = fplot(lagrangepolynomials(p, 0 .. 2)...)
f scatter!(p, [0, 0, 0], color=:tomato)
scatter!(p, [1, 1, 1], color=:blue)
f
Maclaurin polynomials
function maclaurin_polynomial(f, n)
= parameter(domain(f))
x sum([derivativeat(f, 0.0, k) / factorial(k) * x^k for k = 0:n])
end
= Sin(-pi .. pi)
f = maclaurin_polynomial(f, 1)
p1 = maclaurin_polynomial(f, 3)
p3 = maclaurin_polynomial(f, 5)
p5 fplot(f, p1, p3, p5)
Cubic Hermite interpolation polynomials
= -1 .. 2
I = monomials(0:3, I)
m = vcat([[ValueAtLF(x), DerivativeAtLF(x)] for x = endpoints(I)]...)
s = [sⱼ(mᵢ) for mᵢ = m, sⱼ = s]
A = inv(A) * m
h
fplot(h...)
4.1.2 Parametric curves
Lissajous curve
= parameter(0 .. 2π)
x = ParametricCurve(cos(x), sin(2x))
u = 0.075 * sin(100x) * UnitNormal(u)
v = 0.025 * ParametricCurve(sin(200x), cos(200x))
w fplot(u, u + v, u + w)
Interpolate points
= stack([[0.0, 0.0], [1.5, 1.0], [2.0, 0.0], [1.5, -1.0], [0.0, 0.0]])
points = polynomialinterpolation(points)
u
= fplot(u)
fig, ax scatter!(ax, points, color=:tomato)
fig
4.1.3 Monomials
fplot(monomials(0:100, 0 .. 1)...)
4.1.4 Functions of two variables
Create the function \(f : [0, 5\pi]^2 \to \mathbb{R}, \quad f(\mathbf{x}) = \sin x_1 \sin x_2\)
= makefunction(x -> exp(-hypot(x[1], x[2])^2 / 20) * cos(x[1]) * cos(x[2]), -2π .. 2π, -2π .. 2π); f
By default the plot is a view down from positive \(z\) direction
fplot3d(f, mesh=9)
Create a 3D plot using Axis3
and switch of the mesh off since CairoMakie
does not handle hidden lines.
= Figure()
fig Axis3(fig[1, 1])
fplot3d!(f, npoints=250, mesh=nothing)
fig
A good 3D plot is obtained using GLMakie
:
activate!()
GLMakie.= Figure()
fig Axis3(fig[1, 1])
fplot3d!(f, mesh=19, npoints=250)
fig
Multivariate polynomial \(f(x, y) = x^2 y - y\)
= MPolynomial([2 1; 0 1], [1.0, -1.0], QHat)
g = Figure()
fig Axis3(fig[1, 1])
fplot3d!(g)
fig
Multivariate monomials
mmonomials(2, 3, QHat) |> components |> reverse |> fplot3d
Plot gradient of product function
activate!()
CairoMakie.= ProductFunction(Sin(0 .. 2π), Sin(0 .. 2π))
g = fplot3d(g, mesh=nothing)
p vplot!(gradient(g), npoints=9, lengthscale=0.3)
p