Advertisement
Guest User

Untitled

a guest
Jul 6th, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.76 KB | None | 0 0
  1. kill(all)$
  2. load("lrats");
  3. isolate_wrt_times : true$
  4.  
  5. /* the three equations */
  6. eq1: (x1-x)^2+(y1-y)^2+(z1-z)^2=l1^2$
  7. eq2: (x2-x)^2+(y2-y)^2+(z2-z)^2=l2^2$
  8. eq3: (x3-x)^2+(y3-y)^2+(z3-z)^2=l3^2$
  9.  
  10. /* expand */
  11. eq1_expanded : fullratsimp(expand(eq1))$
  12. eq2_expanded : fullratsimp(expand(eq2))$
  13. eq3_expanded : fullratsimp(expand(eq3))$
  14.  
  15. /* subtract eq2 and eq3 from eq1 */
  16. eq1_m_eq2 : rat(eq1_expanded - eq2_expanded)$
  17. eq1_m_eq3 : rat(eq1_expanded - eq3_expanded)$
  18.  
  19. result : solve( [eq1_m_eq2, eq1_m_eq3],[x,y])$
  20.  
  21. /* substitute some 'patterned and beautiful' shared subexpressions to simplify the expressions */
  22. result : lratsubst( [x1^2+y1^2+z1^2=w1, x2^2 + y2^2 + z2^2 = w2, x3^2 + y3^2 + z3^2 = w3 ], result )$
  23. result : lratsubst( [(y1-y2)*z3 + (y3-y1)*z2 + (y2-y3)*z1=v1, (x2-x1)*z3 + (x1-x3)*z2 + (x3-x2)*z1=v2, (x2-x1)*y3+(x1-x3)*y2+(x3-x2)*y1=d], result)$
  24.  
  25. disp("Result after substitutions:")$
  26. disp(result)$
  27.  
  28. x_result : expand(isolate(rhs(result[1][1]),z));
  29. y_result : expand(isolate(rhs(result[1][2]),z));
  30.  
  31. /* insert resulting x and y into eq1 */
  32. eq1_substituted : subst(x_result, x, eq1_expanded)$
  33. eq1_substituted : subst(y_result, y, eq1_substituted)$
  34.  
  35. z_final : solve(eq1_substituted,z)[1]$
  36.  
  37. /* boooom */
  38. z_final : rat( z_final )$
  39. disp( "z independent:")$
  40. disp( z_final )$
  41.  
  42. /* trying to improve on the form, but doesn't work :( */
  43. /* this one should simplify the first subexpression inside the sqrt as well as the denominator of the whole expression and a whole lot of other places, but it doesn't have any effect :( */
  44. z_final : lratsubst( [%t19^2+%t16^2=c1], z_final);
  45.  
  46. /* also I can't find out how to factor out the obvious common factors and constansts like '2' */
  47. /* this doesn't work: */
  48. z_final : factorsum( z_final );
  49.  
  50. disp("finished")$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement