2014-05-01 83 views
0

我有一個問題,其中有一個規範的解決方案,任何旋轉和鏡像(軸上)是另一種解決方案。 爲了避免由於旋轉引起的多重解決方案的問題,我已經在約束條件中設置了矢量應該儘可能與軸對齊。 「鏡像」解決方案現在是我的問題。基本上有些值可以有正解或負解。 這給我2^d解決方案的大小d的問題。 我嘗試使用assume並修正了一些始終爲正的值,這應該可以解決問題,但solve仍然是創建負面解決方案。在Maxima中避免一些解決方案

這是我到目前爲止的代碼:

/* A parameter w0 in (0,1] */ 
assume(w0>=0); 
assume(w0<1); 
d:2$ 
/* d+1 extra points, the is one at x=0, for a total fo d+2 points */ 
s:d+1$ 
/* The unknown are w (weights of the first component) and x_S vectors of dimension d */ 
v:append([w1],makelist(x[i-s*floor(i/s)+1,floor(i/s)+1],i,0,d*s-1)); 
/* The different constraints */ 
e:append(
    /* The sum of weights is 1 */ 
    [w0+s*w1-1=0], 
    /* Some of the components are 0 to be aligned with the axis */ 
    flatten(makelist(makelist(x[i,j]=0,j,i+1,d),i,1,s-1)), 
    /* The mean is 0 */ 
    makelist(sum(x[i,j],i,1,s)=0,j,1,d), 
    /* All vectors have length squared of x[1,1]^2, x[1,:] is skipped as only its first component is non-zero*/ 
    makelist(sum(x[i,j]^2,j,1,d)-x[1,1]^2=0,i,2,s), 
    /* The diagonal of the covariance matrix is 1, w0*0 +w1*sum(x_i^2)=1*/ 
    makelist(w1*sum(x[i,j]^2,i,1,s)-1=0,j,1,d), 
    /* The off-diagonal elements are 0. The dependancy on w1 can be eliminated since the equation is =0. */ 
    flatten(makelist(makelist(sum(x[i,jj]*x[i,jj+j],i,1,s)=0,j,1,d-jj),jj,1,d-1)) 
); 
/* THIS IS NOT WORKING AS I EXPECTED, I WANT SOLUTION ONLY WITH x[i,i]>0 */ 
assume(x[1,1]>0,x[2,2]>0); 
solution:solve(e,v)$ 
number_solutions=length(solution); 

有沒有辦法迫使solve探索只是問題的一些解決方案?

SOLUTION: 繼羅伯特的評論,我能得到「規範」的解決方案如下:

check_canonical(sol):=block([], 
    /* Extract the expression x[i,i]=... */ 
    diag_expr0:makelist(sublist(sol,lambda([e],(if lhs(e)=x[i,i] then true else false))),i,1,d), 
    diag_expr1:flatten(diag_expr0), 
    /* Get the right hand side */ 
    diag_expr2:makelist(rhs(diag_expr1[i]),i,1,d), 
    /* Check for the rhs to be positive */ 
    pos_diag:sublist(diag_expr2,lambda([e],if e>0 then true else false)), 
    /* If all the elelment are positive, then this is a canonical solution */ 
    if length(pos_diag)=d then true else false 
)$ 
canonical_solution:flatten(sublist(solutions,check_canonical)); 

我不是千里馬的專家,但它的工作原理,但我認爲這將是避免探索不符合某些標準的解決方案更有趣。

回答

1

solve不會嘗試過濾該組解決方案。您將不得不篩選solve返回的結果。看看sublist

相關問題