我正在使用Matlab进行涉及使用符号数组的项目,其中每个符号元素都是布尔值。当我尝试简化表达式时会出现问题。
有时函数simplify
会返回此错误:
使用mupadengine / feval时出错(第157行)
MuPAD错误:错误:第一个参数必须是条件。
[简化:: simplifyCondition]
其他时候,这个错误:
未定义的函数'简化'用于'logical'类型的输入参数。
举一个例子,这里有两个函数,第一个是全加器,第二个是三个向量的元素XOR。
Full Adder:
function [carry, sum] = suma_sing (x,y,z)
if (z == true)
z = 1;
elseif (z == false)
z = 0;
end
sum = (~x & ~y & z) | (~x & y & ~z) | (x & ~y & ~z) | (x & y & z);
carry = (x & z) | (x & y) | (y & z);
return
end
因为我正在使用很多元素,所以公式变得复杂,因此对我来说简化它们非常重要。
工作示例代码:
symMsg = symbmatmake('x',1,5) %defines an array filled with sybolic
variables x1, x2, x3, x4 and x5
symMsg2 = symMsg %defines an array filled with sybolic variables y1, y2, y3, y4 and y5
symMsg(end+1) = 1;
symMsg2(end+1) = 1;
symMsg(end+1:end+3)= 0; %% add some 1 and 0
symMsg2(end+1:end+3)= 1;
sum = sym(zeros(1,length(symMsg)));
auxc = 0;
for i=1:length(symMsg)
[auxc,auxs] = suma_sing(symMsg(end+1-i), symMsg2(end+1-i),auxc);
sum(end+1-i) = auxs;
end
display(sum)
sum = simplify(sum);
display(sum);
我的主要程序基本上是在做这样的操作,所以我想我的数据类型可能会发生变化(尽管在调试时它仍然显示为sym)