在Maxima中避免一些解决方案

时间:2014-05-01 18:12:53

标签: maxima

我有一个问题,那里有一个规范的解决方案,任何旋转和镜像(在轴上)是另一种解决方案。 为了避免由于旋转引起的多解决问题,我设置了约束,即在可能的情况下矢量应该与轴对齐。 “镜子”解决方案现在是我的问题。 基本上一些值可以具有正解或负解。 这为2^d大小d问题提供了assume解决方案。 我尝试使用solve并将一些值固定为正值,这应该可以解决问题,但/* 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

有没有办法强迫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}}

我不是Maxima的专家,但它确实有效,但我认为避免探索不符合某些标准的解决方案会更有趣。

1 个答案:

答案 0 :(得分:1)

solve不会尝试过滤解决方案集。您必须过滤solve返回的结果。看看sublist

相关问题