obliczenia_naukowe/l2/6.jl
2024-11-11 00:40:18 +01:00

57 lines
1.1 KiB
Julia
Executable file

#!/usr/bin/env julia
# Jacek Poziemski 272389
import Pkg
Pkg.add("Plots")
using Plots
"""
seq(x::Float64, c::Float64)::Float64
Calculate `x^2 + c`.
# Arguments
- `x::Float64`: the first argument
- `c::Float64`: the second argument
"""
function seq(x::Float64, c::Float64)::Float64
return x^2 + c
end
cs::Vector{Float64} = [-2.0, -2.0, -2.0, -1.0, -1.0, -1.0, -1.0]
xs::Vector{Float64} = [1.0, 2.0, 1.99999999999999, 1.0, -1.0, 0.75, 0.25]
"""
exp(x::Float64, c::Float64)::Vector{Float64}
Iterate over the seq function 40 times.
# Arguments
- `x::Float64`: the first argument
- `c::Float64`: the second argument
"""
function exp(x::Float64, c::Float64)::Vector{Float64}
ret::Vector{Float64} = []
push!(ret, x)
for i in 1:40
x = seq(x, c)
push!(ret, x)
end
return ret
end
sequences::Vector{Vector{Float64}} = []
for i in 1:7
sequence::Vector{Float64} = exp(xs[i], cs[i])
push!(sequences, sequence)
end
for i in 1:length(sequences)
plot(title = "x_n² + c", xlabel = "n", ylabel = "x_n")
plot!(0:40, sequences[i], label = "x = $(xs[i]), c = $(cs[i])", lw = 2)
png("6.$i.png")
end