12341234
12341234

Reputation: 404

R programming: Linear Equation

How can I state, in R code, a list of certain possible values for a given equation? For example (this is just a random equation feel free to use any formula suitable):

For positive integers a, b, and c with the formula x^3 + y^2 = z.

How can I test for all possible combinations of x and y less than or equal to 1000 and c to satisfy the formula and check if the variables are also valid inputs?

Upvotes: 1

Views: 284

Answers (1)

josliber
josliber

Reputation: 44340

You can generate all possible values with expand.grid and then subset to the ones meeting your criteria:

vals <- expand.grid(x=seq(1000), y=seq(1000))
subset(vals, x^3 + y^2 == 108)
#      x  y
# 8003 3  9
# 9002 2 10

Upvotes: 4

Related Questions