2013-06-18 64 views
1

表達式我使用Mathematica來解決與幾何一些簡單的方程組,並且隨後硬編碼在不同的語言†那些解決方案。而不是有許多頁面的代碼,將解決方案編碼爲多項式的根更簡潔。MinimalPolynomial []用於包含符號

讓我們:

Solve[{ 
    dist^2 == xstep^2 + ((h - 2 r)/(NR - 1))^2, 
    dist^2 == (w - 2 r - NC xstep)^2 + (h/2 - r - dist/2)^2 
     },{xstep, dist}] 

這產生一個「非常大的輸出」,以重餾分和平方根和第四根。顯然,兩個解決的變量是四次方程的根源。

請,有MinimalPolynomial []的一個版本,將含有符號表達工作?所需要的就是dist四次的五個係數。

謝謝。

†的「不同的語言」是PostScript和我真的不具備專業知識,寫了// PostScriptForm功能。事實上,在一般情況下,找到重新計算重複表達式和使用「... dup ... roll」之間的最佳平衡將是緩慢的。

+0

你爲什麼要解決表達式中不存在的xx? – agentp

+0

編輯錯誤:替換xstep。抱歉。 – jdaw1

回答

0

我寫了一個包被稱爲「取代」(archived here),該拉出子表達式的層次結構,最小化複雜的表達式的編碼。它包含在舊的MathSource庫中。這裏的描述:

It is often useful, especially when using Mathematica for software development, to apply substitutions to complex expressions to reduce their form. For large expressions, this task can become tedious. Substitutions[] was designed help with the process of finding a useful set of substitutions to simplify an expression.

現在已經很老了,但仍應該工作。

0

減少可能是你想要什麼:

我consolodated你的一些符號組分爲A,B,C(不nesesary,使得它適合在屏幕上)

Reduce[{dist^2 == xstep^2 + (A)^2 && 
     dist^2 == (C - NC xstep)^2 + (B - dist/2)^2 , {xstep, dist}]] 

這就產生了一個相當大的輸出與一堆條件。

如果你已經知道,排除各種degenrate情況下,它有助於指定約束(我做這些了)

$Assumptions = B != 0 && B^2 != 3 C^2 && NC^2 != 3/4; 

注$假設所使用的簡化,但你需要明確地將其添加到表達減少..

Simplify[Reduce[{dist^2 == xstep^2 + (A)^2 && 
    dist^2 == (C - NC xstep)^2 + (B - dist/2)^2 && $Assumptions }, {xstep, dist}]] 

輸出..不是太unwiledy ..根表達式包含你所尋求的係數..

(xstep == 
     Root[9 A^4 - 40 A^2 B^2 + 16 B^4 - 24 A^2 C^2 + 32 B^2 C^2 + 
    16 C^4 + (48 A^2 C NC - 64 B^2 C NC - 
     64 C^3 NC) #1 + (18 A^2 - 40 B^2 - 24 C^2 - 24 A^2 NC^2 + 
     32 B^2 NC^2 + 96 C^2 NC^2) #1^2 + (48 C NC - 
     64 C NC^3) #1^3 + (9 - 24 NC^2 + 16 NC^4) #1^4 &, 1] || 
    xstep == 
    Root[9 A^4 - 40 A^2 B^2 + 16 B^4 - 24 A^2 C^2 + 32 B^2 C^2 + 
     16 C^4 + (48 A^2 C NC - 64 B^2 C NC - 
     64 C^3 NC) #1 + (18 A^2 - 40 B^2 - 24 C^2 - 24 A^2 NC^2 + 
     32 B^2 NC^2 + 96 C^2 NC^2) #1^2 + (48 C NC - 
     64 C NC^3) #1^3 + (9 - 24 NC^2 + 16 NC^4) #1^4 &, 2] || 
    xstep == 
    Root[9 A^4 - 40 A^2 B^2 + 16 B^4 - 24 A^2 C^2 + 32 B^2 C^2 + 
    16 C^4 + (48 A^2 C NC - 64 B^2 C NC - 
     64 C^3 NC) #1 + (18 A^2 - 40 B^2 - 24 C^2 - 24 A^2 NC^2 + 
     32 B^2 NC^2 + 96 C^2 NC^2) #1^2 + (48 C NC - 
     64 C NC^3) #1^3 + (9 - 24 NC^2 + 16 NC^4) #1^4 &, 3] || 
    xstep == 
    Root[9 A^4 - 40 A^2 B^2 + 16 B^4 - 24 A^2 C^2 + 32 B^2 C^2 + 
    16 C^4 + (48 A^2 C NC - 64 B^2 C NC - 
     64 C^3 NC) #1 + (18 A^2 - 40 B^2 - 24 C^2 - 24 A^2 NC^2 + 
     32 B^2 NC^2 + 96 C^2 NC^2) #1^2 + (48 C NC - 
     64 C NC^3) #1^3 + (9 - 24 NC^2 + 16 NC^4) #1^4 &, 4]) && 
    3 A^2 + 4 B dist + xstep (8 C NC + 3 xstep) == 
     4 (B^2 + C^2 + NC^2 xstep^2) 
+0

嗯。進展,謝謝。這與Solve []不同。尤其是,它爲xstep提供了一個根,但不是dist。可以解決xstep多項式,然後求解dist,但是dist應該有一個直接的一步Root。請問,這可以嗎? – jdaw1

+0

嘗試更改解決方案變量的順序('{dist,xstep}')。 – agentp

+0

謝謝,但這並不適用於: $假設=(H \ [Element] Reals && H> 0 && W \ [Element] Reals && W> H && NR \ [Element] Integers && NR> 0 && NC \ [Element] Integers && NC> 0 && R \ [Element] Reals &&R>0); 簡化[Reduce [{(W == 2R +(NC-1)XX)&&(H == R(2NR-4)+ 2YY)&&(4R^2 == XX^2 + YY^2)&& $假設},{R,XX,YY}]] – jdaw1