You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
813 B
Julia
29 lines
813 B
Julia
module RandomPoly
|
|
export random_system
|
|
|
|
using TypedPolynomials
|
|
using Random
|
|
using Distributions
|
|
|
|
# Random polynomial of degree n in m variables
|
|
function random_poly(n, m)
|
|
x = [TypedPolynomials.Variable{Symbol("x[$i]")}() for i in 1:m]
|
|
|
|
monomial_powers=collect(Iterators.product([0:n for _ in 1:m]...))
|
|
monomials = [prod(x.^i) for i in monomial_powers if sum(i) == n]
|
|
|
|
return sum(map(m -> rand(Uniform(-10,10)) * m, monomials))
|
|
end
|
|
|
|
# Generate a system of m random polynomials in m variables
|
|
# of degree d_i randomly chosen between 1 and max_degree
|
|
function random_system(m, max_degree)
|
|
d = rand(1:max_degree, m)
|
|
println("generating system")
|
|
random_polys = [random_poly(d[i], m) for i in 1:m]
|
|
println("done generating system")
|
|
|
|
return random_polys
|
|
end
|
|
end
|