我刚开始学习python,学习变量、输入和基本数学。
我被要求写一个数学练习题,它有以下参数:
ax+by=c, dx+ey=f
a, b, c, d,e, f - the user input and than the program result and write the answear for x, y
我做到了:
number1 = float(input('Insert a number1: '))
number2 = float(input('Insert a number2: '))
number3 = float(input('Insert a number3: '))
number4 = float(input('Insert a number4: '))
number5 = float(input('Insert a number:5 '))
number6 = float(input('Insert a number6: '))
我不会写一个有两个变量的方程
x=number1+2.5*number2-number3 #(it should be looked like ax+by=c)
y=number5+2.5*number6-number4
a x+by=c和dx+ey=f=>;x=(-by+ey-f+c)(a-d)
我也不知道为什么我不能把变量写在print中:
print('the value of x, y is') print((x))
好吧,你必须用编程语言来解决一个有两个变量的方程,如果你不熟悉编程的话就不那么简单了。
先考虑一下手动解决这个问题所需采取的步骤,然后尝试使用Python实现它,我将尝试为您提供一些指导:
1-找到一个数字乘以其中一个方程,这样你就可以“删除”其中一个变量。
两个方程求和(暂时不考虑变量,只考虑它们的系数)
3-在对两个方程求和并存储“新系数”值之后,假设删除了
x
,则应该有如下内容:((e*step_1_number)+b)*y = f*step_1_number + c
4-在前面的步骤中,您将能够找到您的
y
值,之后就很容易找到x
值。我用Python成功地做到了这一点,但我认为如果我只是发布代码,自己尝试解决一些问题,那么这对你没有帮助,祝你好运!
你可以用
matrix
的形式写出上面的方程。使用此方法可以轻松找到
(x,y)
的答案。你只需要解这个矩阵方程。您可以使用
numpy
找到答案。(或者你只需要实现矩阵逆和你自己的乘法)相关问题 更多 >
编程相关推荐