Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
sumiya11 committed Dec 10, 2023
1 parent 0b44905 commit 9c2e620
Show file tree
Hide file tree
Showing 2 changed files with 252 additions and 43 deletions.
293 changes: 252 additions & 41 deletions experimental/linear-algebra/examples.jl
Original file line number Diff line number Diff line change
@@ -1,61 +1,230 @@
using Nemo, Plots


s1 = 20
s2 = 16
begin
p = plot(xlims=(0.0, 5.0), ylims=(0.0, 4), dpi=200, xlabel="x", ylabel="t", xguidefontsize=s1, yguidefontsize=s1, legendfontsize=s2, xtickfontsize=s2, ytickfontsize=s2, xticks=[1,2,3,4,5], yticks=[0,1,2,3,4])
p = plot(
xlims=(0.0, 5.0),
ylims=(0.0, 4),
dpi=200,
xlabel="x",
ylabel="t",
xguidefontsize=s1,
yguidefontsize=s1,
legendfontsize=s2,
xtickfontsize=s2,
ytickfontsize=s2,
xticks=[1, 2, 3, 4, 5],
yticks=[0, 1, 2, 3, 4]
)
scatter!([(1, 1), (4, 1), (2, 3)], color=:blue, markersize=8, alpha=0.7, label=nothing)
plot!([(1, 1), (4, 1), (2, 3), (1,1)], color=:blue, markersize=8, alpha=0.2, fill=true, label=nothing)
plot!(
[(1, 1), (4, 1), (2, 3), (1, 1)],
color=:blue,
markersize=8,
alpha=0.2,
fill=true,
label=nothing
)
savefig("ex1.png")
# p
end

begin
p = plot(xlims=(0.0, 5.0), ylims=(0.0, 4), dpi=200, xlabel="x", ylabel="t", xguidefontsize=s1, yguidefontsize=s1, legendfontsize=s2, xtickfontsize=s2, ytickfontsize=s2, xticks=[1,2,3,4,5], yticks=[0,1,2,3,4])
scatter!([(0, 0), (3, 0), (4, 3), (2, 2), ], color=:blue, markersize=8, alpha=0.7, label=nothing)
plot!([(0, 0), (3, 0), (4, 3), (2, 2), (0,0)], color=:blue, markersize=8, alpha=0.2, fill=true, label=nothing)
p = plot(
xlims=(0.0, 5.0),
ylims=(0.0, 4),
dpi=200,
xlabel="x",
ylabel="t",
xguidefontsize=s1,
yguidefontsize=s1,
legendfontsize=s2,
xtickfontsize=s2,
ytickfontsize=s2,
xticks=[1, 2, 3, 4, 5],
yticks=[0, 1, 2, 3, 4]
)
scatter!(
[(0, 0), (3, 0), (4, 3), (2, 2)],
color=:blue,
markersize=8,
alpha=0.7,
label=nothing
)
plot!(
[(0, 0), (3, 0), (4, 3), (2, 2), (0, 0)],
color=:blue,
markersize=8,
alpha=0.2,
fill=true,
label=nothing
)
savefig("ex2.png")
# p
# p
end

begin
p = plot(xlims=(0.0, 3), ylims=(0.0, 3), dpi=200, xlabel="x", ylabel="t", xguidefontsize=s1, yguidefontsize=s1, legendfontsize=s2, xtickfontsize=s2, ytickfontsize=s2, xticks=[1,2,3,4,5], yticks=[0,1,2,3,4])
scatter!([(0, 0), (0, 1), (0, 2), (2, 2), (1,1), (1,2)], color=:blue, markersize=8, alpha=0.7, label=nothing)
plot!([(0, 0), (2, 2), (0,2),(0, 0)], color=:blue, markersize=8, alpha=0.2, fill=true, label=nothing)
p = plot(
xlims=(0.0, 3),
ylims=(0.0, 3),
dpi=200,
xlabel="x",
ylabel="t",
xguidefontsize=s1,
yguidefontsize=s1,
legendfontsize=s2,
xtickfontsize=s2,
ytickfontsize=s2,
xticks=[1, 2, 3, 4, 5],
yticks=[0, 1, 2, 3, 4]
)
scatter!(
[(0, 0), (0, 1), (0, 2), (2, 2), (1, 1), (1, 2)],
color=:blue,
markersize=8,
alpha=0.7,
label=nothing
)
plot!(
[(0, 0), (2, 2), (0, 2), (0, 0)],
color=:blue,
markersize=8,
alpha=0.2,
fill=true,
label=nothing
)
plot!(0:3, x -> x, linestyle=:dash, color=:red, linewidth=4, alpha=0.3, label=nothing)
savefig("ex3.png")
p
end

begin
p = plot(xlims=(0.0, 3), ylims=(0.0, 3), dpi=200, xlabel="x", ylabel="t", xguidefontsize=s1, yguidefontsize=s1, legendfontsize=s2, xtickfontsize=s2, ytickfontsize=s2, xticks=[1,2,3,4,5], yticks=[0,1,2,3,4])
scatter!([(0, 0), (0, 1), (1,1)], color=:blue, markersize=8, alpha=0.7, label=nothing)
plot!([(0, 0), (0, 1), (1, 1), (0, 0)], color=:blue, markersize=8, alpha=0.2, fill=true, label=nothing)
p = plot(
xlims=(0.0, 3),
ylims=(0.0, 3),
dpi=200,
xlabel="x",
ylabel="t",
xguidefontsize=s1,
yguidefontsize=s1,
legendfontsize=s2,
xtickfontsize=s2,
ytickfontsize=s2,
xticks=[1, 2, 3, 4, 5],
yticks=[0, 1, 2, 3, 4]
)
scatter!([(0, 0), (0, 1), (1, 1)], color=:blue, markersize=8, alpha=0.7, label=nothing)
plot!(
[(0, 0), (0, 1), (1, 1), (0, 0)],
color=:blue,
markersize=8,
alpha=0.2,
fill=true,
label=nothing
)
savefig("ex3-1.png")
p
end

begin
p = plot(xlims=(0.0, 3), ylims=(0.0, 3), dpi=200, xlabel="x", ylabel="t", xguidefontsize=s1, yguidefontsize=s1, legendfontsize=s2, xtickfontsize=s2, ytickfontsize=s2, xticks=[1,2,3,4,5], yticks=[0,1,2,3,4])
scatter!([(0, 0), (2, 0), (1, 1), (1, 0), (0, 1), (0, 2)], color=:blue, markersize=8, alpha=0.7, label=nothing)
plot!([(0, 0), (2, 0), (0, 2), (0, 0)], color=:blue, markersize=8, alpha=0.2, fill=true, label=nothing)
p = plot(
xlims=(0.0, 3),
ylims=(0.0, 3),
dpi=200,
xlabel="x",
ylabel="t",
xguidefontsize=s1,
yguidefontsize=s1,
legendfontsize=s2,
xtickfontsize=s2,
ytickfontsize=s2,
xticks=[1, 2, 3, 4, 5],
yticks=[0, 1, 2, 3, 4]
)
scatter!(
[(0, 0), (2, 0), (1, 1), (1, 0), (0, 1), (0, 2)],
color=:blue,
markersize=8,
alpha=0.7,
label=nothing
)
plot!(
[(0, 0), (2, 0), (0, 2), (0, 0)],
color=:blue,
markersize=8,
alpha=0.2,
fill=true,
label=nothing
)
savefig("ex4.png")
p
end

begin
p = plot(xlims=(0.0, 5), ylims=(0.0, 5), dpi=200, xlabel="x", ylabel="t", xguidefontsize=s1, yguidefontsize=s1, legendfontsize=s2, xtickfontsize=s2, ytickfontsize=s2, xticks=[1,2,3,4,5], yticks=[0,1,2,3,4])
scatter!([(0, 0), (4, 2), (3, 2), (2, 3), (2, 2), (2, 1), (1, 3), (1, 1), (0, 4), (0, 2)], color=:blue, markersize=8, alpha=0.7, label=nothing)
plot!([(0, 0), (4, 2), (0, 4)], color=:blue, markersize=8, alpha=0.2, fill=true, label=nothing)
p = plot(
xlims=(0.0, 5),
ylims=(0.0, 5),
dpi=200,
xlabel="x",
ylabel="t",
xguidefontsize=s1,
yguidefontsize=s1,
legendfontsize=s2,
xtickfontsize=s2,
ytickfontsize=s2,
xticks=[1, 2, 3, 4, 5],
yticks=[0, 1, 2, 3, 4]
)
scatter!(
[(0, 0), (4, 2), (3, 2), (2, 3), (2, 2), (2, 1), (1, 3), (1, 1), (0, 4), (0, 2)],
color=:blue,
markersize=8,
alpha=0.7,
label=nothing
)
plot!(
[(0, 0), (4, 2), (0, 4)],
color=:blue,
markersize=8,
alpha=0.2,
fill=true,
label=nothing
)
savefig("ex5.png")
p
end

begin
p = plot(xlims=(0.0, 3), ylims=(0.0, 3), dpi=200, xlabel="x", ylabel="t", xguidefontsize=s1, yguidefontsize=s1, legendfontsize=s2, xtickfontsize=s2, ytickfontsize=s2, xticks=[1,2,3,4,5], yticks=[0,1,2,3,4])
scatter!([(0, 0), (2, 1), (1, 1), (0,2)], color=:blue, markersize=8, alpha=0.7, label=nothing)
plot!([(0, 0), (2, 1), (0, 2)], color=:blue, markersize=8, alpha=0.2, fill=true, label=nothing)
p = plot(
xlims=(0.0, 3),
ylims=(0.0, 3),
dpi=200,
xlabel="x",
ylabel="t",
xguidefontsize=s1,
yguidefontsize=s1,
legendfontsize=s2,
xtickfontsize=s2,
ytickfontsize=s2,
xticks=[1, 2, 3, 4, 5],
yticks=[0, 1, 2, 3, 4]
)
scatter!(
[(0, 0), (2, 1), (1, 1), (0, 2)],
color=:blue,
markersize=8,
alpha=0.7,
label=nothing
)
plot!(
[(0, 0), (2, 1), (0, 2)],
color=:blue,
markersize=8,
alpha=0.2,
fill=true,
label=nothing
)
savefig("ex5-1.png")
p
end
Expand All @@ -71,10 +240,7 @@ begin
(center=points[3], range=(-pi / 4, asin(2 / sqrt(5))))
]

dranges = [
(center=r.center, drange=first(r.range):piece:last(r.range))
for r in ranges
]
dranges = [(center=r.center, drange=first(r.range):piece:last(r.range)) for r in ranges]

allranges = []
for r in dranges
Expand All @@ -83,22 +249,66 @@ begin
end
end

anim = @animate for i 1:length(allranges)
anim = @animate for i in 1:length(allranges)
center = allranges[i].center
phi = allranges[i].phi

plot(xlims=(0.0, 5.0), ylims=(0.0, 5.0), dpi=200, xlabel="x", ylabel="y", xguidefontsize=16, yguidefontsize=16, legendfontsize=14, xtickfontsize=12, ytickfontsize=12, xticks=[1,2,3,4,5], yticks=[0,1,2,3,4,5])
plot(
xlims=(0.0, 5.0),
ylims=(0.0, 5.0),
dpi=200,
xlabel="x",
ylabel="y",
xguidefontsize=16,
yguidefontsize=16,
legendfontsize=14,
xtickfontsize=12,
ytickfontsize=12,
xticks=[1, 2, 3, 4, 5],
yticks=[0, 1, 2, 3, 4, 5]
)
scatter!(points, color=:blue, markersize=8, alpha=0.7, label=nothing)
plot!(vcat(points, first(points)), color=:blue, markersize=8, alpha=0.2, fill=true, label=nothing)
plot!(
vcat(points, first(points)),
color=:blue,
markersize=8,
alpha=0.2,
fill=true,
label=nothing
)

# for j in 1:length(points) - 1
# plot!([points[j]...], [points[j+1]...], linestyle=:dash, color=:red)
# end
# plot!(, points[1], linestyle=:dash, color=:red)

plot!(0:5, x -> 1, linestyle=:dash, color=:red, linewidth=4, alpha=0.3, label=nothing)
plot!(0:5, x -> 2x-1, linestyle=:dash, color=:red, linewidth=4, alpha=0.3, label=nothing)
plot!(0:5, x -> -x + 5, linestyle=:dash, color=:red, linewidth=4, alpha=0.3, label=nothing)

plot!(
0:5,
x -> 1,
linestyle=:dash,
color=:red,
linewidth=4,
alpha=0.3,
label=nothing
)
plot!(
0:5,
x -> 2x - 1,
linestyle=:dash,
color=:red,
linewidth=4,
alpha=0.3,
label=nothing
)
plot!(
0:5,
x -> -x + 5,
linestyle=:dash,
color=:red,
linewidth=4,
alpha=0.3,
label=nothing
)

e1 = rad * exp(phi * im)
e2 = e1 * exp(pi * im)
Expand All @@ -111,24 +321,27 @@ begin

scatter!((from_e...,), label=nothing)
scatter!((to_e...,), label=nothing)
plot!([(from_e...,), (to_e...,)], linewidth=4, color=:black, label="\$w \\cdot (x,y) = const\$")

plot!(
[(from_e...,), (to_e...,)],
linewidth=4,
color=:black,
label="\$w \\cdot (x,y) = const\$"
)
end
gif(anim, "anim_fps15.gif", fps=30, loop=0)
end

y = ax + b
w2 * y - w1 * x = 0
y = w1 / w2 x
y = w1 / w2 * x

# plot!(points, color=:blue, fill=true, alpha=0.2)

ra = range(0.0, 2pi, 35)
rad = 1.0
j = 1


anim = @animate for i 0:n-1
anim = @animate for i in 0:(n - 1)
plot(xlims=(0.0, 5.0), ylims=(-1.0, 5.0))
scatter!(orig_points_for_scatter, color=:blue, markersize=4)
plot!(orig_points_for_scatter, color=:blue, fill=true, alpha=0.2)
Expand Down Expand Up @@ -200,7 +413,7 @@ begin
n = length(ra)
points = copy(orig_points)
j = 1
anim = @animate for i 0:n-1
anim = @animate for i in 0:(n - 1)
global j, orig_points, points, ra, rad, n, orig_points_for_scatter

plot(xlims=(0.0, 5.0), ylims=(-1.0, 5.0))
Expand Down Expand Up @@ -281,5 +494,3 @@ A2 = evaluate(A, [x, y, 3])
A1 = evaluate(A, [x, 4, 9])

##########


2 changes: 0 additions & 2 deletions experimental/linear-algebra/threads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,3 @@ end)
basis = map(_ -> Monom(rand(1:COUNT[]), 0), 1:($n))
basis, pool
end)


0 comments on commit 9c2e620

Please sign in to comment.