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.

27 lines
735 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(Normal()) * 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)
random_polys = [random_poly(d[i], m) for i in 1:m]
return random_polys
end
end