2

Logical circuit

I had to calculate every output on this logical circuit, and i dont have any experience with electronic.

So, i searched for the meaning of the symbols and i build my program on Matlab.

Somebody can look and help me if i did it wrong or pointing a better way to do?

Here is my Matlab code:

for A = 0 : 1
  for B = 0 : 1
    for C = 0 : 1
      for D = 0 : 1
          if A ~= B
              E = 1;
          else
              E = 0;
          end

          if B == 0
              F = 1;
          else
              F = 0;
          end

          if C == 0
              G = 1;
          else
              G = 0;
          end

          if E == 1 && F == 1 && C == 1
              H = 1;
          else
              H = 0;
          end

          if G == 1 || D == 1
              I = 0;
          else
              I = 1;
          end

          if H == 1 && I == 1
              Y = 0;
          else
              Y = 1;
          end

          disp(['Se A=' num2str(A) ', B=' num2str(B) ', C=' num2str(C) ' e D=' num2str(D) ' => Y=' num2str(Y)]);
      end
    end
  end
end
Machavity
  • 30,841
  • 27
  • 92
  • 100

1 Answers1

2

Your code will produce the right results, but you could use MATLAB's built-in functions for boolean algebra.

for A = 0 : 1
  for B = 0 : 1
    for C = 0 : 1
      for D = 0 : 1
        Y = ~((xor(A,B) & ~B & C) & ~(~C | D));
        disp(['Se A=' num2str(A) ', B=' num2str(B) ', C=' num2str(C) ' e D=' num2str(D) ' => Y=' num2str(Y)]);
      end
    end
  end
end
codingEnthusiast
  • 3,800
  • 2
  • 25
  • 37