从Scheme中的线性方程求解X?

发布于 2024-08-08 08:59:36 字数 598 浏览 2 评论 0原文

我想解决x。我该如何在Scheme中做到这一点?

T1-F2=0
F1+T2=GM-Gm
Cos(60)(2.5*Gm+x*GM-l*F1)-l*Sin(60)*T1=0

F1=0.1*T1
F2=0.3*T2
M=20
m=80
l=5

我的尝试是:

(lambda T1 .            ;; T1=F2
(lambda F2 .            ;; F2=0.3*T2
 (lambda F1 .           ;; F1=0.1*T1
  (lambda Gm .
   ( lambda GM .
     (- 
      ( * 1/2
        ( - 
          ( + ( * 2.5 Gm ) ( * x GM ) )    ;; solve x
          5 * F1
        )
      )
      ( * 
        ( * 10 1/sqrt(3) ) 
        T1 
      )
     )
   ) 80
  ) 20
 ) ( * 0.1 T1 )
 ) ( * 0.3 T2 )
) F2

;; ???   F1+T2=GM-Gm

I want to solve x. How can I do it in Scheme?

T1-F2=0
F1+T2=GM-Gm
Cos(60)(2.5*Gm+x*GM-l*F1)-l*Sin(60)*T1=0

F1=0.1*T1
F2=0.3*T2
M=20
m=80
l=5

My try is:

(lambda T1 .            ;; T1=F2
(lambda F2 .            ;; F2=0.3*T2
 (lambda F1 .           ;; F1=0.1*T1
  (lambda Gm .
   ( lambda GM .
     (- 
      ( * 1/2
        ( - 
          ( + ( * 2.5 Gm ) ( * x GM ) )    ;; solve x
          5 * F1
        )
      )
      ( * 
        ( * 10 1/sqrt(3) ) 
        T1 
      )
     )
   ) 80
  ) 20
 ) ( * 0.1 T1 )
 ) ( * 0.3 T2 )
) F2

;; ???   F1+T2=GM-Gm

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风轻花落早 2024-08-15 08:59:36

我不确定你为什么要创建所有这些高阶函数,在我看来,这只会让事情变得混乱。相反,请摘掉你的代数帽子,并对此进行一些思考。

您有 5 个方程,其中有 5 个未知数。 (F1、F2、T1、T2 和 x)。正如您所看到的,其中三个方程(T1-F2=0F1=0.1*T1F2=0.3*T2)很简单为了实现这一点,因此通过替换立即消除 3 个未知数,例如,在您看到 T1 的任何地方,将 F2 粘贴在其位置,因为 T1=F2。 (如果你像我一样并且不太相信自己,你可以随时将最终的数字代入原始方程以验证你是否正确。)

然后你还剩下两个方程。如果您可以手动求解方程,您将得到 x 的方程,并且您只需编写一个程序来评估它。否则,请使用包含 2 个方程和 2 个未知数的系统的一般方法。

一般来说,要求解未知数 x1, x2, ... xn 的线性方程,给定已知量,将它们放入标准形式(其中 A 和 B 系数已知):

A11*x1 + A12*x2 + A13*x3 ... + A1n*xn = B1
A21*x1 + A22*x2 + A23*x3 ... + A2n*xn = B2
 .
 .
 .
An1*x1 + An2*x2 + An3*x3 ... + Ann*xn = Bn

或者,以矩阵形式:

Ax = B

这有多种求解方法对于 x,请参阅维基百科;大型系统的标准方法。

对于包含 2 个方程和 2 个未知数的系统:

A11*x1 + A12*x2 = B1
A21*x1 + A22*x2 = B2

方程很少,您可以继续使用 Cramer 的规则。克莱默法则对于大 N 来说是很糟糕的,一方面是因为数值精度和对错误的敏感性,另一方面是因为它与其他技术相比非常慢。但对于 N=2 来说就很好了。

I'm not sure why you're creating all those higher-order functions, it just makes things confusing in my opinion. Instead, dust off your algebra hat and put a little thinking into this.

You've got 5 equations with 5 unknowns. (F1, F2, T1, T2, and x). Three of those equations (T1-F2=0, F1=0.1*T1 and F2=0.3*T2) are trivial, as you seem to realize, so eliminate 3 of the unknowns right off the bat through substitution, e.g. everywhere you see T1, stick F2 in its place since T1=F2. (If you're like me and you don't quite trust yourself, you can always substitute the final numbers back into the original equations to verify that you got it right.)

Then you have two equations left. If you can solve the equations by hand, you'll have an equation for x and you just have to write a program to evaluate it. Otherwise, use the general approach with a system of 2 equations and 2 unknowns.

In general, to solve linear equations for unknowns x1, x2, ... xn, given known quantities, put them into standard form (where the A and B coefficients are known):

A11*x1 + A12*x2 + A13*x3 ... + A1n*xn = B1
A21*x1 + A22*x2 + A23*x3 ... + A2n*xn = B2
 .
 .
 .
An1*x1 + An2*x2 + An3*x3 ... + Ann*xn = Bn

or, in matrix form:

Ax = B

This has many ways to solve for x, see wikipedia; the standard method for large systems.

For a system of 2 equations and 2 unknowns:

A11*x1 + A12*x2 = B1
A21*x1 + A22*x2 = B2

there's few enough equations that you can go ahead and use Cramer's Rule. Cramer's Rule is awful for large N, both because of numerical accuracy and sensivity to error, and because it's very slow compared to other techniques. But for N=2 it's fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文