필터 지우기
필터 지우기

How to construct and evaluate a boolean expression using symbols?

조회 수: 16 (최근 30일)
Jay Vaidya
Jay Vaidya 2020년 11월 15일
답변: Walter Roberson 2020년 11월 15일
If I have a boolean expression that is
y = (x1barx2)(x3barx4bar)(x3barx5)
I am currently using a simple 1 and 0 matrix to evaluate this sometimes manually and sometimes in a for a loop. However, it is difficult to do the same for larger expressions. Is there a way that I can evaluate these expressions using symbols like the ones we have poly2sym()? In other words, using and or logical operators and the values of the variables, can I find the answer of any boolean expression without using a for a loop as my expressions should less time to evaluate compared to the other part of the code.

채택된 답변

Walter Roberson
Walter Roberson 2020년 11월 15일
[X1, X2, X3, X4, X5] = ndgrid([false,true]);
X1bar = ~X1;
X3bar = ~X3;
X4bar = ~X4;
X1barvX2 = X1bar | X2;
X3barvX4bar = X3bar | X4bar;
X3barvX5 = X3bar | X5;
y = (X1barvX2) & (X3barvX4bar) & (X3barvX5);
y_table = [X1(y), X2(y), X3(y), X4(y), X5(y)];
disp(y_table)
0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 1 0 1 0 1 1 0 1 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 0 1 0 1 0 1 1 0 1 1 1 1 0 1 0 0 0 1 1 0 1 0 1 1 1 1 0 1 1

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by