Created
August 15, 2019 23:47
-
-
Save cocomoff/9b73b6154d9788da912ab5850ffa5583 to your computer and use it in GitHub Desktop.
Legendre変換のお勉強: (x, y)ではなく(p, w)で関数を表す
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
using Plots | |
# 適当な2次関数,導関数,接線の方程式 | |
f(x; b=-3, d=2) = (b .+ x) .^2 .+ d | |
df(x; b=-3, d=2) = 2 .* (b .+ x) | |
fₜₐₙ(x, xₚ; b=-3, d=2) = df(xₚ) .* (x .- xₚ) .+ f(xₚ, b=b, d=d) | |
# 関数 | |
x = 1:0.1:5; | |
y = f(x); | |
# 導関数 | |
x₁ = 4 | |
y₁ = fₜₐₙ(x, x₁) | |
x₂ = 3 | |
y₂ = fₜₐₙ(x, x₂) | |
x₃ = 2 | |
y₃ = fₜₐₙ(x, x₃) | |
plot(x, y, ylims=(0,6), lw=3, linecolor=:red) | |
plot!(x, y₁, lw=1.5, linecolor=:blue, label="tan(x=$x₁)") | |
plot!(x, y₂, lw=1.5, linecolor=:blue, label="tan(x=$x₂)") | |
plot!(x, y₃, lw=1.5, linecolor=:blue, label="tan(x=$x₃)") | |
# legendre | |
x = -1:0.1:7; | |
y = f(x); | |
# 導関数 | |
x₁ = 4 | |
y₁ = fₜₐₙ(x, x₁) | |
y₁₀ = fₜₐₙ(0, x₁) | |
x₂ = 1 | |
y₂ = fₜₐₙ(x, x₂) | |
y₂₀ = fₜₐₙ(0, x₂) | |
plot(x, y, lw=3, linecolor=:red) | |
plot!(x, y₁, lw=1.5, linecolor=:blue, label="tan(x=$x₁)") | |
plot!(x, y₂, lw=1.5, linecolor=:green, label="tan(x=$x₂)") | |
plot!([0], seriestype=:vline, linecolor=:black, lw=0.5, label="") | |
plot!([0], [y₁₀], seriestype=:scatter, color=:blue, label="") | |
plot!([0], [y₂₀], seriestype=:scatter, color=:green, label="") | |
# vline!(x=0, lw=3, linecolor=:red) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment