简体   繁体   English

R编程:线性方程

[英]R programming: Linear Equation

How can I state, in R code, a list of certain possible values for a given equation? 如何用R代码说明给定方程式的某些可能值的列表? 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. 对于具有公式x ^ 3 + y ^ 2 = z的正整数a,b和c。

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? 如何测试x和y小于或等于1000和c的所有可能组合以满足公式,并检查变量是否也是有效输入?

You can generate all possible values with expand.grid and then subset to the ones meeting your criteria: 您可以使用expand.grid生成所有可能的值,然后子集expand.grid符合条件的值:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM