tags:

views:

147

answers:

1

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
+3  A: 

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.

Jason S